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.

69 line
2.1KB

  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. public function __construct(
  19. ReductionCartRepositoryQuery $query,
  20. ReductionCartSolver $reductionCartSolver,
  21. PriceSolver $priceSolver
  22. ) {
  23. $this->query = $query;
  24. $this->reductionCartSolver = $reductionCartSolver;
  25. $this->priceSolver = $priceSolver;
  26. }
  27. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  28. {
  29. $query->orderBy('id');
  30. return $query;
  31. }
  32. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  33. {
  34. if($this->section) {
  35. $query->filterBySection($this->section);
  36. }
  37. $query->filterIsOnlineAndOffline();
  38. return $query;
  39. }
  40. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  41. {
  42. return $query;
  43. }
  44. // getReductionCartByCode
  45. public function getByCode(string $code, $query = null)
  46. {
  47. $query = $this->createDefaultQuery($query);
  48. $query->filterByCode($code);
  49. $reductionCarts = $query->find();
  50. $findReductionCart = null;
  51. foreach ($reductionCarts as $reductionCart) {
  52. if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
  53. $findReductionCart = $reductionCart;
  54. }
  55. }
  56. return $findReductionCart;
  57. }
  58. }