Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ProductRepositoryQuery.php 6.4KB

3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
2 år sedan
3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  7. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  8. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  9. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  10. class ProductRepositoryQuery extends AbstractRepositoryQuery
  11. {
  12. protected bool $isJoinProductFamily = false;
  13. protected bool $isJoinSections = false;
  14. protected bool $isJoinProductFamilySectionProperties = false;
  15. public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
  16. {
  17. parent::__construct($repository, 'product', $paginator);
  18. }
  19. public function orderByDefault(): \Lc\SovBundle\Repository\AbstractRepositoryQuery
  20. {
  21. return $this->orderBy('position', 'ASC');
  22. }
  23. public function joinProductFamily(): self
  24. {
  25. if (!$this->isJoinProductFamily) {
  26. $this->isJoinProductFamily = true;
  27. return $this
  28. ->innerJoin('.productFamily', 'productFamily')
  29. ->addSelect('productFamily');
  30. }
  31. return $this;
  32. }
  33. public function filterBySection(SectionInterface $section): self
  34. {
  35. $this->joinProductFamilySectionProperties(false);
  36. $this->andWhereSection('productFamilySectionProperties', $section);
  37. $this->andWhere('productFamilySectionProperties.status = 1');
  38. return $this;
  39. }
  40. public function filterByMerchantViaSection(MerchantInterface $merchant)
  41. {
  42. $this->joinProductFamilySectionProperties(false);
  43. $this->joinSections(false);
  44. $this->andWhereMerchant('section', $merchant);
  45. $this->andWhere('productFamilySectionProperties.status = 1');
  46. }
  47. public function joinSections(bool $addSelect = true): self
  48. {
  49. if (!$this->isJoinSections) {
  50. $this->isJoinSections = true;
  51. $this->leftJoin('productFamilySectionProperties.section', 'section');
  52. if ($addSelect) {
  53. $this->addSelect('section');
  54. }
  55. }
  56. return $this;
  57. }
  58. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  59. {
  60. $this->joinProductFamily();
  61. if (!$this->isJoinProductFamilySectionProperties) {
  62. $this->isJoinProductFamilySectionProperties = true;
  63. $this->leftJoin('productFamily.productFamilySectionProperties', 'productFamilySectionProperties');
  64. if ($addSelect) {
  65. //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)
  66. //$this->addSelect('productFamilySectionProperties');
  67. }
  68. }
  69. return $this;
  70. }
  71. public function filterIsOnline(): self
  72. {
  73. $this->joinProductFamily();
  74. $this->andWhereStatus('productFamily', 1);
  75. $this->andWhereStatus($this->id, 1);
  76. return $this;
  77. }
  78. public function filterIsOnlineAndOffline(): self
  79. {
  80. $this->joinProductFamily();
  81. $this->andWhere('productFamily.status >= 0');
  82. $this->andWhere('.status >=0');
  83. return $this;
  84. }
  85. public function filterIsOnSale(): self
  86. {
  87. $this->joinProductFamily();
  88. $this->andWhere('productFamily.saleStatus = 1');
  89. return $this;
  90. }
  91. public function filterIsOriginProduct(): self
  92. {
  93. $this->andWhere('.originProduct = 1');
  94. return $this;
  95. }
  96. public function filterByProductFamily(ProductFamilyInterface $productFamily): self
  97. {
  98. return $this->andWhereEqual('productFamily', $productFamily);
  99. }
  100. public function filterIsNotAvailableQuantitySupplierUnlimited(): self
  101. {
  102. $this->andWhere('productFamily.availableQuantitySupplierUnlimited != 1');
  103. return $this;
  104. }
  105. public function filterAvailableQuantityNegative(): self
  106. {
  107. $this->andWhere(
  108. $this->query->expr()->orX(
  109. $this->query->expr()->andX(
  110. $this->query->expr()->orX(
  111. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  112. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  113. ),
  114. 'productFamily.availableQuantity < 0 '
  115. ),
  116. $this->query->expr()->andX(
  117. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  118. 'product.availableQuantity < 0 '
  119. )
  120. )
  121. );
  122. $this->setParameter(
  123. 'behaviorCountStockByProductFamily',
  124. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  125. );
  126. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  127. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  128. return $this;
  129. }
  130. public function filterAvailableQuantitySupplierNegative(): self
  131. {
  132. $this->andWhere(
  133. $this->query->expr()->orX(
  134. $this->query->expr()->andX(
  135. $this->query->expr()->orX(
  136. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  137. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  138. ),
  139. 'productFamily.availableQuantitySupplier < 0 '
  140. ),
  141. $this->query->expr()->andX(
  142. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  143. 'product.availableQuantitySupplier < 0 '
  144. )
  145. )
  146. );
  147. $this->setParameter(
  148. 'behaviorCountStockByProductFamily',
  149. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  150. );
  151. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  152. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  153. return $this;
  154. }
  155. }