Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

55 lines
2.4KB

  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(
  26. $qb->expr()->orX(
  27. $qb->expr()->andX(
  28. $qb->expr()->orX(
  29. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  30. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  31. ),
  32. 'productFamily.availableQuantity < 0 '
  33. ),
  34. $qb->expr()->andX(
  35. 'productFamily.behaviorCountStock LIKE :behaviorCountStockByProduct',
  36. 'e.availableQuantity < 0 '
  37. )
  38. )
  39. );
  40. $qb->setParameter('behaviorCountStockByProductFamily', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY);
  41. $qb->setParameter('behaviorCountStockByMeasure', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  42. $qb->setParameter('behaviorCountStockByProduct', ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  43. $qb->groupBy('productFamily.id');
  44. return $qb->getQuery()->getResult();
  45. }
  46. }