|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Reduction;
-
- use Lc\CaracoleBundle\Repository\SectionStoreTrait;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
- use Lc\CaracoleBundle\Repository\AbstractStore;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
-
- class ReductionCartStore extends AbstractStore
- {
- use SectionStoreTrait;
-
- protected ReductionCartRepositoryQuery $query;
- protected ReductionCartSolver $reductionCartSolver;
- protected PriceSolver $priceSolver;
-
- public function __construct(
- ReductionCartRepositoryQuery $query,
- ReductionCartSolver $reductionCartSolver,
- PriceSolver $priceSolver
- ) {
- $this->query = $query;
- $this->reductionCartSolver = $reductionCartSolver;
- $this->priceSolver = $priceSolver;
- }
-
- public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->orderBy('id');
- return $query;
- }
-
- public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- if($this->section) {
- $query->filterBySection($this->section);
- }
- $query->filterIsOnlineAndOffline();
- return $query;
- }
-
- public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- return $query;
- }
-
- // getReductionCartByCode
- public function getByCode(string $code, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterByCode($code);
- $reductionCarts = $query->find();
-
- $findReductionCart = null;
- foreach ($reductionCarts as $reductionCart) {
- if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
- $findReductionCart = $reductionCart;
- }
- }
- return $findReductionCart;
- }
- }
|