Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

119 lines
3.9KB

  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. return $query ;
  25. }
  26. public function findAll()
  27. {
  28. $query = $this->findByMerchantQuery() ;
  29. $query = $this->joinRelations($query) ;
  30. return $query->getQuery()->getResult() ;
  31. }
  32. public function findAllOnline()
  33. {
  34. $query = $this->findByMerchantQuery() ;
  35. $query = $this->joinRelations($query) ;
  36. $query->andWhere('e.status = 1') ;
  37. return $query->getQuery()->getResult() ;
  38. }
  39. public function findOneBySlug($slug)
  40. {
  41. $query = $this->findByMerchantQuery() ;
  42. $query->andWhere('e.slug = :slug')->setParameter('slug',$slug) ;
  43. $query->andWhere('e.status = 1');
  44. return $query->getQuery()->getOneOrNullResult() ;
  45. }
  46. public function getProductFamiliesByCategory($category){
  47. $query = $this->findByMerchantQuery() ;
  48. $query = $this->joinRelations($query) ;
  49. $query->andWhere(':category MEMBER OF e.productCategories');
  50. $query->setParameter('category', $category->getId());
  51. $query->andWhere('e.status = 1');
  52. return $query->getQuery()->getResult() ;
  53. }
  54. public function getProductFamiliesNovelties(){
  55. $query = $this->findByMerchantQuery();
  56. $query = $this->joinRelations($query) ;
  57. $query->andWhere('e.status = 1');
  58. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  59. ->setParameter('now', new \DateTime()) ;
  60. return $query->getQuery()->getResult() ;
  61. }
  62. public function getProductFamiliesLargeVolumes(){
  63. $query = $this->findByMerchantQuery() ;
  64. $query = $this->joinRelations($query) ;
  65. $query->andWhere('e.status = 1');
  66. $query->andWhere('e.propertyLargeVolume = 1');
  67. return $query->getQuery()->getResult() ;
  68. }
  69. public function getProductFamiliesOrganics(){
  70. $query = $this->findByMerchantQuery() ;
  71. $query = $this->joinRelations($query) ;
  72. $query->andWhere('e.status = 1');
  73. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  74. return $query->getQuery()->getResult() ;
  75. }
  76. public function findByTerms($terms, $maxResults = false)
  77. {
  78. $query = $this->findByMerchantQuery() ;
  79. $query = $this->joinRelations($query) ;
  80. $query->andWhere('e.status = 1');
  81. $query->andWhere('e.title LIKE :terms');
  82. $query->setParameter(':terms', '%'.$terms.'%') ;
  83. if($maxResults) {
  84. $query->setMaxResults($maxResults) ;
  85. }
  86. return $query->getQuery()->getResult() ;
  87. }
  88. }