You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2KB

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