選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

75 行
2.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  4. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  5. use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
  6. use Lc\CaracoleBundle\Repository\AbstractStore;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ReductionCartStore extends AbstractStore
  10. {
  11. use MerchantStoreTrait;
  12. protected ReductionCartRepositoryQuery $query;
  13. protected ReductionCartSolver $reductionCartSolver;
  14. protected PriceSolver $priceSolver;
  15. public function __construct(
  16. ReductionCartRepositoryQuery $query,
  17. ReductionCartSolver $reductionCartSolver,
  18. PriceSolver $priceSolver
  19. )
  20. {
  21. $this->query = $query;
  22. $this->reductionCartSolver = $reductionCartSolver;
  23. $this->priceSolver = $priceSolver;
  24. }
  25. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  26. {
  27. $query->orderBy('id');
  28. return $query;
  29. }
  30. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  31. {
  32. $this->addFilterByMerchantRequired($query);
  33. $query->filterIsOnlineAndOffline();
  34. return $query;
  35. }
  36. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  37. {
  38. return $query;
  39. }
  40. // getReductionCartByCode
  41. public function getByCode(string $code, $query = null)
  42. {
  43. $query = $this->createDefaultQuery($query);
  44. $query->filterByCode($code);
  45. $reductionCarts = $query->find();
  46. $findReductionCart = null;
  47. foreach ($reductionCarts as $reductionCart) {
  48. if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
  49. $findReductionCart = $reductionCart;
  50. }
  51. }
  52. return $findReductionCart;
  53. }
  54. //Toutes les reductionCart d'un utilisateur inter/merchant
  55. public function getByUserOutOfContext(UserInterface $user, $query = null)
  56. {
  57. $query = $this->createQuery($query);
  58. $query->filterIsOnlineAndOffline();
  59. $query->filterByUser($user);
  60. return $query->find();
  61. }
  62. }