You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.3KB

  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, 'r', $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', 'pf');
  27. //$qb->addSelect('pf'); ???
  28. }
  29. return $this;
  30. }
  31. public function filterBySection(SectionInterface $section):self
  32. {
  33. $this->joinProductFamilySectionProperties(false);
  34. $this->andWhereSection('pfsp', $section);
  35. $this->andWhere('pfsp.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('pf.productFamilySectionProperties', 'pfsp');
  44. if ($addSelect) {
  45. $this->addSelect('pfsp');
  46. }
  47. }
  48. return $this;
  49. }
  50. public function filterIsOnline():self
  51. {
  52. $this->joinProductFamily();
  53. $this->andWhereStatus('pf', 1);
  54. $this->andWhereStatus($this->id, 1);
  55. return $this;
  56. }
  57. public function filterBehaviorCountStock() :self
  58. {
  59. $this->andWhere(
  60. $this->expr()->orX(
  61. $this->expr()->andX(
  62. $this->expr()->orX(
  63. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  64. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  65. ),
  66. 'productFamily.availableQuantity < 0 '
  67. ),
  68. $this->expr()->andX(
  69. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  70. 'e.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. }