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.

128 lines
4.2KB

  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->leftJoin('e.productCategories', 'cat');
  82. $query->addSelect('cat') ;
  83. $query->orderBy('e.position', 'ASC');
  84. $query->andWhere('e.status = 1');
  85. $query->andWhere('e.title LIKE :terms OR cat.title LIKE :terms');
  86. $query->setParameter(':terms', '%'.$terms.'%') ;
  87. $query->groupBy('e.id') ;
  88. if($maxResults) {
  89. $query->setMaxResults($maxResults) ;
  90. }
  91. return $query->getQuery()->getResult() ;
  92. }
  93. }