No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ProductFamilyRepository.php 3.6KB

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