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.

80 lines
2.7KB

  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. public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
  13. {
  14. parent::__construct($repository, 'r', $paginator);
  15. }
  16. public function orderByDefault(): \Lc\SovBundle\Repository\AbstractRepositoryQuery
  17. {
  18. return $this->orderBy('position', 'ASC');
  19. }
  20. public function joinProductFamily():self
  21. {
  22. if (!$this->isJoinProductFamily) {
  23. $this->isJoinProductFamily = true;
  24. return $this
  25. ->innerJoin('.productFamily', 'pf');
  26. //$qb->addSelect('pf'); ???
  27. }
  28. return $this;
  29. }
  30. public function filterBySection(SectionInterface $section):self
  31. {
  32. $this->joinProductFamily();
  33. $this->andWhereSection('pf', $section);
  34. return $this;
  35. }
  36. public function filterIsOnline():self
  37. {
  38. $this->joinProductFamily();
  39. $this->andWhereStatus('pf', 1);
  40. $this->andWhereStatus($this->id, 1);
  41. return $this;
  42. }
  43. public function filterBehaviorCountStock() :self
  44. {
  45. $this->andWhere(
  46. $this->expr()->orX(
  47. $this->expr()->andX(
  48. $this->expr()->orX(
  49. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  50. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  51. ),
  52. 'productFamily.availableQuantity < 0 '
  53. ),
  54. $this->expr()->andX(
  55. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  56. 'e.availableQuantity < 0 '
  57. )
  58. )
  59. );
  60. $this->setParameter(
  61. 'behaviorCountStockByProductFamily',
  62. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  63. );
  64. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  65. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  66. return $this;
  67. }
  68. }