Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ReductionCatalogRepository.php 3.6KB

pirms 4 gadiem
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  5. use Symfony\Component\Validator\Constraints\DateTime;
  6. /**
  7. * @method ReductionCatalogInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ReductionCatalogInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ReductionCatalogInterface[] findAll()
  10. * @method ReductionCatalogInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class ReductionCatalogRepository extends BaseRepository implements DefaultRepositoryInterface
  13. {
  14. public function getInterfaceClass()
  15. {
  16. return ReductionCatalogInterface::class;
  17. }
  18. public function getReductionCatalogByProductFamily($productFamily, $user)
  19. {
  20. $query = $this->findByMerchantQuery();
  21. $query->andWhere('e.status = 1');
  22. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  23. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  24. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  25. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  26. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  27. $query->setParameter('user', $user);
  28. $query->setParameter('groupUser', $user->getGroupUsers());
  29. $query->setParameter('productFamily', $productFamily);
  30. $query->setParameter('productCategory', $productFamily->getProductCategories());
  31. $query->setParameter('supplier', $productFamily->getSupplier());
  32. return $query->getQuery()->getResult();
  33. }
  34. public function getReductionCatalogByProductFamilyConditions($productFamilyIds, $user)
  35. {
  36. $query = $this->findByMerchantQuery();
  37. $query->andWhere('e.status = 1');
  38. $query->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)');
  39. $query->leftJoin('e.productFamilies', 'pfs') ;
  40. $query->addSelect('pfs') ;
  41. $query->leftJoin('e.productFamily', 'pf') ;
  42. $query->addSelect('pf') ;
  43. $query->leftJoin('e.productCategories', 'pc') ;
  44. $query->addSelect('pc') ;
  45. if($user){
  46. $query->andWhere(':user MEMBER OF e.users OR e.users is empty');
  47. $query->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty');
  48. $query->setParameter('user', $user);
  49. $query->setParameter('groupUser', $user->getGroupUsers());
  50. }
  51. $query->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty');
  52. $query->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty');
  53. $query->andWhere(':supplier MEMBER OF e.suppliers OR e.suppliers is empty');
  54. $query->setParameter('productFamily', $productFamilyIds['ids']);
  55. $query->setParameter('productCategory', $productFamilyIds['categories']);
  56. $query->setParameter('supplier', $productFamilyIds['suppliers']);
  57. $query->setParameter(':now', new \DateTime());
  58. return $query->getQuery()->getResult();
  59. }
  60. }