Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProductFamilyRepository.php 3.3KB

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /**
  7. * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  10. */
  11. class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface
  12. {
  13. public function getInterfaceClass()
  14. {
  15. return ProductFamilyInterface::class;
  16. }
  17. public function joinRelations($query)
  18. {
  19. $query->leftJoin('e.productCategories', 'cat');
  20. $query->addSelect('cat') ;
  21. $query->innerJoin('e.products', 'pfp');
  22. $query->addSelect('pfp') ;
  23. return $query ;
  24. }
  25. public function findAll()
  26. {
  27. $query = $this->findByMerchantQuery() ;
  28. $query = $this->joinRelations($query) ;
  29. return $query->getQuery()->getResult() ;
  30. }
  31. public function getProductFamiliesByCategory($category){
  32. $query = $this->findByMerchantQuery() ;
  33. $query = $this->joinRelations($query) ;
  34. $query->andWhere(':category MEMBER OF e.productCategories');
  35. $query->setParameter('category', $category->getId());
  36. $query->andWhere('e.status = 1');
  37. return $query->getQuery()->getResult() ;
  38. }
  39. public function getProductFamiliesNovelties(){
  40. $query = $this->findByMerchantQuery();
  41. $query = $this->joinRelations($query) ;
  42. $query->andWhere('e.status = 1');
  43. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  44. ->setParameter('now', new \DateTime()) ;
  45. return $query->getQuery()->getResult() ;
  46. }
  47. public function getProductFamiliesLargeVolumes(){
  48. $query = $this->findByMerchantQuery() ;
  49. $query = $this->joinRelations($query) ;
  50. $query->andWhere('e.status = 1');
  51. $query->andWhere('e.propertyLargeVolume = 1');
  52. return $query->getQuery()->getResult() ;
  53. }
  54. public function getProductFamiliesOrganics(){
  55. $query = $this->findByMerchantQuery() ;
  56. $query = $this->joinRelations($query) ;
  57. $query->andWhere('e.status = 1');
  58. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  59. return $query->getQuery()->getResult() ;
  60. }
  61. public function findByTerms($terms, $maxResults = false)
  62. {
  63. $query = $this->findByMerchantQuery() ;
  64. $query = $this->joinRelations($query) ;
  65. $query->andWhere('e.status = 1');
  66. $query->andWhere('e.title LIKE :terms');
  67. $query->setParameter(':terms', '%'.$terms.'%') ;
  68. if($maxResults) {
  69. $query->setMaxResults($maxResults) ;
  70. }
  71. return $query->getQuery()->getResult() ;
  72. }
  73. }