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.

147 lines
5.1KB

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