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 3.6KB

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