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.

64 lines
1.9KB

  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\Repository\RepositoryQueryInterface;
  8. class ReductionCartStore extends AbstractStore
  9. {
  10. use MerchantStoreTrait;
  11. protected ReductionCartRepositoryQuery $query;
  12. protected ReductionCartSolver $reductionCartSolver;
  13. protected PriceSolver $priceSolver;
  14. public function __construct(
  15. ReductionCartRepositoryQuery $query,
  16. ReductionCartSolver $reductionCartSolver,
  17. PriceSolver $priceSolver
  18. ) {
  19. $this->query = $query;
  20. $this->reductionCartSolver = $reductionCartSolver;
  21. $this->priceSolver = $priceSolver;
  22. }
  23. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  24. {
  25. $query->orderBy('id');
  26. return $query;
  27. }
  28. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  29. {
  30. $this->addFilterByMerchantRequired($query);
  31. $query->filterIsOnlineAndOffline();
  32. return $query;
  33. }
  34. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  35. {
  36. return $query;
  37. }
  38. // getReductionCartByCode
  39. public function getByCode(string $code, $query = null)
  40. {
  41. $query = $this->createDefaultQuery($query);
  42. $query->filterByCode($code);
  43. $reductionCarts = $query->find();
  44. $findReductionCart = null;
  45. foreach ($reductionCarts as $reductionCart) {
  46. if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
  47. $findReductionCart = $reductionCart;
  48. }
  49. }
  50. return $findReductionCart;
  51. }
  52. }