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.

ProductFamilyRepository.php 4.1KB

преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. return $query->getQuery()->getResult() ;
  63. }
  64. public function getProductFamiliesLargeVolumes(){
  65. $query = $this->findByMerchantQuery() ;
  66. $query = $this->joinRelations($query) ;
  67. $query->andWhere('e.status = 1');
  68. $query->andWhere('e.propertyLargeVolume = 1');
  69. return $query->getQuery()->getResult() ;
  70. }
  71. public function getProductFamiliesOrganics(){
  72. $query = $this->findByMerchantQuery() ;
  73. $query = $this->joinRelations($query) ;
  74. $query->andWhere('e.status = 1');
  75. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  76. return $query->getQuery()->getResult() ;
  77. }
  78. public function findByTerms($terms, $maxResults = false)
  79. {
  80. $query = $this->findByMerchantQuery() ;
  81. $query = $this->joinRelations($query) ;
  82. $query->andWhere('e.status = 1');
  83. $query->andWhere('e.title LIKE :terms OR cat.title LIKE :terms');
  84. $query->setParameter(':terms', '%'.$terms.'%') ;
  85. $query->groupBy('e.id') ;
  86. if($maxResults) {
  87. $query->setMaxResults($maxResults) ;
  88. }
  89. return $query->getQuery()->getResult() ;
  90. }
  91. }