您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProductFamilyRepository.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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');
  84. $query->setParameter(':terms', '%'.$terms.'%') ;
  85. if($maxResults) {
  86. $query->setMaxResults($maxResults) ;
  87. }
  88. return $query->getQuery()->getResult() ;
  89. }
  90. }