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.

138 lines
4.6KB

  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. $query->orderBy('e.position', 'ASC');
  25. return $query ;
  26. }
  27. public function findAll()
  28. {
  29. $query = $this->findByMerchantQuery() ;
  30. $query = $this->joinRelations($query) ;
  31. return $query->getQuery()->getResult() ;
  32. }
  33. public function findAllOnline()
  34. {
  35. $query = $this->findByMerchantQuery() ;
  36. $query = $this->joinRelations($query) ;
  37. $query->andWhere('e.status = 1') ;
  38. return $query->getQuery()->getResult() ;
  39. }
  40. public function findOneBySlug($slug)
  41. {
  42. $query = $this->findByMerchantQuery() ;
  43. $query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ;
  44. $query->andWhere('e.status = 1');
  45. return $query->getQuery()->getOneOrNullResult() ;
  46. }
  47. public function getProductFamiliesByCategory($category){
  48. $query = $this->findByMerchantQuery() ;
  49. $query = $this->joinRelations($query) ;
  50. $query->andWhere(':category MEMBER OF e.productCategories');
  51. $query->setParameter('category', $category->getId());
  52. $query->andWhere('e.status = 1');
  53. $query->orderBy('e.position', 'ASC');
  54. return $query->getQuery()->getResult() ;
  55. }
  56. public function getProductFamiliesNovelties(){
  57. $query = $this->findByMerchantQuery();
  58. $query = $this->joinRelations($query) ;
  59. $query->andWhere('e.status = 1');
  60. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  61. ->setParameter('now', new \DateTime()) ;
  62. $query->orderBy('e.createdAt', 'DESC');
  63. return $query->getQuery()->getResult() ;
  64. }
  65. public function getProductFamiliesLargeVolumes(){
  66. $query = $this->findByMerchantQuery() ;
  67. $query = $this->joinRelations($query) ;
  68. $query->andWhere('e.status = 1');
  69. $query->andWhere('e.propertyLargeVolume = 1');
  70. return $query->getQuery()->getResult() ;
  71. }
  72. public function getProductFamiliesOrganics(){
  73. $query = $this->findByMerchantQuery() ;
  74. $query = $this->joinRelations($query) ;
  75. $query->andWhere('e.status = 1');
  76. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  77. return $query->getQuery()->getResult() ;
  78. }
  79. public function findByTerms($terms, $maxResults = false)
  80. {
  81. $query = $this->findByMerchantQuery() ;
  82. $query->leftJoin('e.productCategories', 'cat');
  83. $query->addSelect('cat') ;
  84. $query->orderBy('e.position', 'ASC');
  85. $query->andWhere('e.status = 1');
  86. $query->andWhere('e.title LIKE :terms OR cat.title LIKE :terms');
  87. $query->setParameter(':terms', '%'.$terms.'%') ;
  88. $query->groupBy('e.id') ;
  89. if($maxResults) {
  90. $query->setMaxResults($maxResults) ;
  91. }
  92. return $query->getQuery()->getResult() ;
  93. }
  94. public function getProductFamiliesBySection($section)
  95. {
  96. $query = $this->findByMerchantQuery() ;
  97. $query = $this->joinRelations($query) ;
  98. $query->andWhere(':section MEMBER OF e.sections')
  99. ->setParameter('section', $section) ;
  100. return $query->getQuery()->getResult() ;
  101. }
  102. }