您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProductRepositoryQuery.php 4.7KB

3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ProductRepositoryQuery extends AbstractRepositoryQuery
  10. {
  11. protected bool $isJoinProductFamily =false;
  12. protected bool $isJoinProductFamilySectionProperties =false;
  13. public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
  14. {
  15. parent::__construct($repository, 'product', $paginator);
  16. }
  17. public function orderByDefault(): \Lc\SovBundle\Repository\AbstractRepositoryQuery
  18. {
  19. return $this->orderBy('position', 'ASC');
  20. }
  21. public function joinProductFamily():self
  22. {
  23. if (!$this->isJoinProductFamily) {
  24. $this->isJoinProductFamily = true;
  25. return $this
  26. ->innerJoin('.productFamily', 'productFamily')
  27. ->addSelect('productFamily');
  28. }
  29. return $this;
  30. }
  31. public function filterBySection(SectionInterface $section):self
  32. {
  33. $this->joinProductFamilySectionProperties(false);
  34. $this->andWhereSection('productFamilySectionProperties', $section);
  35. $this->andWhere('productFamilySectionProperties.status = 1');
  36. return $this;
  37. }
  38. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  39. {
  40. $this->joinProductFamily();
  41. if (!$this->isJoinProductFamilySectionProperties) {
  42. $this->isJoinProductFamilySectionProperties = true;
  43. $this->leftJoin('productFamily.productFamilySectionProperties', 'productFamilySectionProperties');
  44. if ($addSelect) {
  45. $this->addSelect('productFamilySectionProperties');
  46. }
  47. }
  48. return $this;
  49. }
  50. public function filterIsOnline():self
  51. {
  52. $this->joinProductFamily();
  53. $this->andWhereStatus('productFamily', 1);
  54. $this->andWhereStatus($this->id, 1);
  55. return $this;
  56. }
  57. public function filterAvailableQuantityNegative() :self
  58. {
  59. $this->andWhere(
  60. $this->query->expr()->orX(
  61. $this->query->expr()->andX(
  62. $this->query->expr()->orX(
  63. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  64. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  65. ),
  66. 'productFamily.availableQuantity < 0 '
  67. ),
  68. $this->query->expr()->andX(
  69. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  70. 'product.availableQuantity < 0 '
  71. )
  72. )
  73. );
  74. $this->setParameter(
  75. 'behaviorCountStockByProductFamily',
  76. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  77. );
  78. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  79. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  80. return $this;
  81. }
  82. public function filterAvailableQuantitySupplierNegative() :self
  83. {
  84. $this->andWhere(
  85. $this->query->expr()->orX(
  86. $this->query->expr()->andX(
  87. $this->query->expr()->orX(
  88. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  89. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  90. ),
  91. 'productFamily.availableQuantitySupplier < 0 '
  92. ),
  93. $this->query->expr()->andX(
  94. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  95. 'product.availableQuantitySupplier < 0 '
  96. )
  97. )
  98. );
  99. $this->setParameter(
  100. 'behaviorCountStockByProductFamily',
  101. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  102. );
  103. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  104. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  105. return $this;
  106. }
  107. }