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.

56 lines
2.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ProductInterface;
  5. use Lc\ShopBundle\Model\ProductFamily;
  6. /**
  7. * @method ProductInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ProductInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ProductInterface[] findAll()
  10. * @method ProductInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class ProductRepository extends BaseRepository implements DefaultRepositoryInterface
  13. {
  14. public function getInterfaceClass()
  15. {
  16. return ProductInterface::class;
  17. }
  18. public function findProductByAvailabilitiesNegative()
  19. {
  20. $qb = $this->createQueryBuilder('e');
  21. $qb->innerJoin('e.productFamily', 'productFamily');
  22. $qb->addSelect('productFamily');
  23. $qb->where('productFamily.merchant = :currentMerchant');
  24. $qb->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId());
  25. $qb->andWhere('productFamily.status = 1');
  26. $qb->andWhere(
  27. $qb->expr()->orX(
  28. $qb->expr()->andX(
  29. $qb->expr()->orX(
  30. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  31. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  32. ),
  33. 'productFamily.availableQuantity < 0 '
  34. ),
  35. $qb->expr()->andX(
  36. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  37. 'e.availableQuantity < 0 '
  38. )
  39. )
  40. );
  41. $qb->setParameter('behaviorCountStockByProductFamily', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY);
  42. $qb->setParameter('behaviorCountStockByMeasure', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  43. $qb->setParameter('behaviorCountStockByProduct', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  44. $qb->groupBy('productFamily.id');
  45. return $qb->getQuery()->getResult();
  46. }
  47. }