Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProductFamilyRepository.php 3.9KB

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ProductFamilyInterface;
  5. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  6. use Lc\ShopBundle\Model\ProductFamily;
  7. /**
  8. * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
  9. * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
  10. * @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface
  13. {
  14. public function getInterfaceClass()
  15. {
  16. return ProductFamilyInterface::class;
  17. }
  18. public function joinRelations($query)
  19. {
  20. $query->leftJoin('e.productCategories', 'cat');
  21. $query->addSelect('cat') ;
  22. $query->innerJoin('e.products', 'pfp');
  23. $query->addSelect('pfp') ;
  24. return $query ;
  25. }
  26. public function findAll()
  27. {
  28. $query = $this->findByMerchantQuery() ;
  29. $query = $this->joinRelations($query) ;
  30. return $query->getQuery()->getResult() ;
  31. }
  32. public function findAllOnline()
  33. {
  34. $query = $this->findByMerchantQuery() ;
  35. $query = $this->joinRelations($query) ;
  36. $query->andWhere('e.status = 1') ;
  37. return $query->getQuery()->getResult() ;
  38. }
  39. public function findOneBySlug($slug)
  40. {
  41. $query = $this->findByMerchantQuery() ;
  42. $query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ;
  43. $query->andWhere('e.status = 1');
  44. return $query->getQuery()->getOneOrNullResult() ;
  45. }
  46. public function getProductFamiliesByCategory($category){
  47. $query = $this->findByMerchantQuery() ;
  48. $query = $this->joinRelations($query) ;
  49. $query->andWhere(':category MEMBER OF e.productCategories');
  50. $query->setParameter('category', $category->getId());
  51. $query->andWhere('e.status = 1');
  52. return $query->getQuery()->getResult() ;
  53. }
  54. public function getProductFamiliesNovelties(){
  55. $query = $this->findByMerchantQuery();
  56. $query = $this->joinRelations($query) ;
  57. $query->andWhere('e.status = 1');
  58. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  59. ->setParameter('now', new \DateTime()) ;
  60. return $query->getQuery()->getResult() ;
  61. }
  62. public function getProductFamiliesLargeVolumes(){
  63. $query = $this->findByMerchantQuery() ;
  64. $query = $this->joinRelations($query) ;
  65. $query->andWhere('e.status = 1');
  66. $query->andWhere('e.propertyLargeVolume = 1');
  67. return $query->getQuery()->getResult() ;
  68. }
  69. public function getProductFamiliesOrganics(){
  70. $query = $this->findByMerchantQuery() ;
  71. $query = $this->joinRelations($query) ;
  72. $query->andWhere('e.status = 1');
  73. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  74. return $query->getQuery()->getResult() ;
  75. }
  76. public function findByTerms($terms, $maxResults = false)
  77. {
  78. $query = $this->findByMerchantQuery() ;
  79. $query = $this->joinRelations($query) ;
  80. $query->andWhere('e.status = 1');
  81. $query->andWhere('e.title LIKE :terms');
  82. $query->setParameter(':terms', '%'.$terms.'%') ;
  83. if($maxResults) {
  84. $query->setMaxResults($maxResults) ;
  85. }
  86. return $query->getQuery()->getResult() ;
  87. }
  88. }