|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Product;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- 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 $isJoinSections = false;
- protected bool $isJoinProductFamilySectionProperties = false;
-
- public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'product', $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', 'productFamily')
- ->addSelect('productFamily');
- }
- return $this;
- }
-
- public function filterBySection(SectionInterface $section): self
- {
- $this->joinProductFamilySectionProperties(false);
- $this->andWhereSection('productFamilySectionProperties', $section);
- $this->andWhere('productFamilySectionProperties.status = 1');
-
- return $this;
- }
-
-
- public function filterByMerchantViaSection(MerchantInterface $merchant)
- {
- $this->joinProductFamilySectionProperties(false);
- $this->joinSections(false);
- $this->andWhereMerchant('section', $merchant);
- $this->andWhere('productFamilySectionProperties.status = 1');
- }
-
- public function joinSections(bool $addSelect = true): self
- {
- if (!$this->isJoinSections) {
- $this->isJoinSections = true;
-
- $this->leftJoin('productFamilySectionProperties.section', 'section');
- if ($addSelect) {
- $this->addSelect('section');
- }
- }
- return $this;
- }
-
- public function joinProductFamilySectionProperties(bool $addSelect = true): self
- {
- $this->joinProductFamily();
-
- if (!$this->isJoinProductFamilySectionProperties) {
- $this->isJoinProductFamilySectionProperties = true;
-
- $this->leftJoin('productFamily.productFamilySectionProperties', 'productFamilySectionProperties');
- if ($addSelect) {
- //NB : Ici le select est en commentaire car si il est actif doctrine n'hydrate pas correectement ProductFamilySectionProperties (si filtre sur section les ProductFamilySectionProperties des autres sections ne sont pas chargé et ça peut être problématique pr la gestion des stocks)
-
- //$this->addSelect('productFamilySectionProperties');
- }
- }
- return $this;
- }
-
-
- public function filterIsOnline(): self
- {
- $this->joinProductFamily();
- $this->andWhereStatus('productFamily', 1);
- $this->andWhereStatus($this->id, 1);
- return $this;
- }
-
- public function filterIsOnSale(): self
- {
- $this->joinProductFamily();
- $this->andWhere('productFamily.saleStatus = 1');
- return $this;
- }
-
-
- public function filterIsOriginProduct(): self
- {
- $this->andWhere('.originProduct = 1');
- return $this;
- }
-
-
- public function filterByProductFamily(ProductFamilyInterface $productFamily): self
- {
- return $this->andWhereEqual('productFamily', $productFamily);
- }
-
-
- public function filterIsNotAvailableQuantitySupplierUnlimited(): self
- {
- $this->andWhere('productFamily.availableQuantitySupplierUnlimited != 1');
- return $this;
- }
-
-
- public function filterAvailableQuantityNegative(): self
- {
-
- $this->andWhere(
- $this->query->expr()->orX(
- $this->query->expr()->andX(
- $this->query->expr()->orX(
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
- ),
- 'productFamily.availableQuantity < 0 '
- ),
- $this->query->expr()->andX(
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
- 'product.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(
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
- ),
- 'productFamily.availableQuantitySupplier < 0 '
- ),
- $this->query->expr()->andX(
- 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
- 'product.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;
- }
-
-
- }
|