Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

65 rindas
1.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  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 SectionStoreTrait;
  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. if($this->section) {
  31. $query->filterBySection($this->section);
  32. }
  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. }