|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Product;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
-
- class ProductRepositoryQuery extends AbstractRepositoryQuery
- {
- protected bool $isJoinProductFamily =false;
- protected bool $isJoinProductFamilySectionProperties =false;
-
- public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
- public function orderByDefault(): \Lc\SovBundle\Repository\AbstractRepositoryQuery
- {
- return $this->orderBy('position', 'ASC');
- }
-
- public function joinProductFamily():self
- {
- if (!$this->isJoinProductFamily) {
- $this->isJoinProductFamily = true;
-
- return $this
- ->innerJoin('.productFamily', 'pf')
- ->addSelect('pf');
- }
- return $this;
- }
-
- public function filterBySection(SectionInterface $section):self
- {
- $this->joinProductFamilySectionProperties(false);
- $this->andWhereSection('pfsp', $section);
- $this->andWhere('pfsp.status = 1');
-
- return $this;
- }
- public function joinProductFamilySectionProperties(bool $addSelect = true): self
- {
- $this->joinProductFamily();
-
- if (!$this->isJoinProductFamilySectionProperties) {
- $this->isJoinProductFamilySectionProperties = true;
-
- $this->leftJoin('pf.productFamilySectionProperties', 'pfsp');
- if ($addSelect) {
- $this->addSelect('pfsp');
- }
- }
- return $this;
- }
-
-
- public function filterIsOnline():self
- {
- $this->joinProductFamily();
- $this->andWhereStatus('pf', 1);
- $this->andWhereStatus($this->id, 1);
- return $this;
- }
-
-
- public function filterAvailableQuantityNegative() :self
- {
-
- $this->andWhere(
- $this->query->expr()->orX(
- $this->query->expr()->andX(
- $this->query->expr()->orX(
- 'pf.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
- 'pf.behaviorCountStock LIKE :behaviorCountStockByMeasure'
- ),
- 'pf.availableQuantity < 0 '
- ),
- $this->query->expr()->andX(
- 'pf.behaviorCountStock LIKE :behaviorCountStockByProduct',
- 'r.availableQuantity < 0 '
- )
- )
- );
- $this->setParameter(
- 'behaviorCountStockByProductFamily',
- ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
- );
- $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
- $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
- return $this;
- }
-
- public function filterAvailableQuantitySupplierNegative() :self
- {
-
- $this->andWhere(
- $this->query->expr()->orX(
- $this->query->expr()->andX(
- $this->query->expr()->orX(
- 'pf.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
- 'pf.behaviorCountStock LIKE :behaviorCountStockByMeasure'
- ),
- 'pf.availableQuantitySupplier < 0 '
- ),
- $this->query->expr()->andX(
- 'pf.behaviorCountStock LIKE :behaviorCountStockByProduct',
- 'r.availableQuantitySupplier < 0 '
- )
- )
- );
- $this->setParameter(
- 'behaviorCountStockByProductFamily',
- ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
- );
- $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
- $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
- return $this;
- }
-
-
- }
|