Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

79 linhas
2.6KB

  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;
  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. return $this;
  41. }
  42. public function filterBehaviorCountStock() :self
  43. {
  44. $this->andWhere(
  45. $this->expr()->orX(
  46. $this->expr()->andX(
  47. $this->expr()->orX(
  48. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  49. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  50. ),
  51. 'productFamily.availableQuantity < 0 '
  52. ),
  53. $this->expr()->andX(
  54. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  55. 'e.availableQuantity < 0 '
  56. )
  57. )
  58. );
  59. $this->setParameter(
  60. 'behaviorCountStockByProductFamily',
  61. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  62. );
  63. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  64. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  65. return $this;
  66. }
  67. }