選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

182 行
6.2KB

  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 filterIsOnSale(): self
  79. {
  80. $this->joinProductFamily();
  81. $this->andWhere('productFamily.saleStatus = 1');
  82. return $this;
  83. }
  84. public function filterIsOriginProduct(): self
  85. {
  86. $this->andWhere('.originProduct = 1');
  87. return $this;
  88. }
  89. public function filterByProductFamily(ProductFamilyInterface $productFamily): self
  90. {
  91. return $this->andWhereEqual('productFamily', $productFamily);
  92. }
  93. public function filterIsNotAvailableQuantitySupplierUnlimited(): self
  94. {
  95. $this->andWhere('productFamily.availableQuantitySupplierUnlimited != 1');
  96. return $this;
  97. }
  98. public function filterAvailableQuantityNegative(): self
  99. {
  100. $this->andWhere(
  101. $this->query->expr()->orX(
  102. $this->query->expr()->andX(
  103. $this->query->expr()->orX(
  104. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  105. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  106. ),
  107. 'productFamily.availableQuantity < 0 '
  108. ),
  109. $this->query->expr()->andX(
  110. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  111. 'product.availableQuantity < 0 '
  112. )
  113. )
  114. );
  115. $this->setParameter(
  116. 'behaviorCountStockByProductFamily',
  117. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  118. );
  119. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  120. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  121. return $this;
  122. }
  123. public function filterAvailableQuantitySupplierNegative(): self
  124. {
  125. $this->andWhere(
  126. $this->query->expr()->orX(
  127. $this->query->expr()->andX(
  128. $this->query->expr()->orX(
  129. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  130. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  131. ),
  132. 'productFamily.availableQuantitySupplier < 0 '
  133. ),
  134. $this->query->expr()->andX(
  135. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  136. 'product.availableQuantitySupplier < 0 '
  137. )
  138. )
  139. );
  140. $this->setParameter(
  141. 'behaviorCountStockByProductFamily',
  142. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  143. );
  144. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  145. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  146. return $this;
  147. }
  148. }