Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

ProductFamilyRepository.php 4.3KB

4 lat temu
4 lat temu
4 lat temu
4 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. }