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.

97 lines
3.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. /**
  7. * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ProductFamilyInterface[] findAll()
  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->innerJoin('e.supplier', 'pfs');
  25. $query->addSelect('pfs') ;
  26. return $query ;
  27. }
  28. public function getProductFamiliesByCategory($category){
  29. $query = $this->findByMerchantQuery() ;
  30. $query = $this->joinRelations($query) ;
  31. $query->andWhere(':category MEMBER OF e.productCategories');
  32. $query->setParameter('category', $category->getId());
  33. $query->andWhere('e.status = 1');
  34. return $query->getQuery()->getResult() ;
  35. }
  36. public function getProductFamiliesNovelties(){
  37. $query = $this->findByMerchantQuery();
  38. $query = $this->joinRelations($query) ;
  39. $query->andWhere('e.status = 1');
  40. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  41. ->setParameter('now', new \DateTime()) ;
  42. return $query->getQuery()->getResult() ;
  43. }
  44. public function getProductFamiliesLargeVolumes(){
  45. $query = $this->findByMerchantQuery() ;
  46. $query = $this->joinRelations($query) ;
  47. $query->andWhere('e.status = 1');
  48. $query->andWhere('e.propertyLargeVolume = 1');
  49. return $query->getQuery()->getResult() ;
  50. }
  51. public function getProductFamiliesOrganics(){
  52. $query = $this->findByMerchantQuery() ;
  53. $query = $this->joinRelations($query) ;
  54. $query->andWhere('e.status = 1');
  55. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  56. return $query->getQuery()->getResult() ;
  57. }
  58. public function findByTerms($terms, $maxResults = false)
  59. {
  60. $query = $this->findByMerchantQuery() ;
  61. $query = $this->joinRelations($query) ;
  62. $query->andWhere('e.status = 1');
  63. $query->andWhere('e.title LIKE :terms');
  64. $query->setParameter(':terms', '%'.$terms.'%') ;
  65. if($maxResults) {
  66. $query->setMaxResults($maxResults) ;
  67. }
  68. return $query->getQuery()->getResult() ;
  69. }
  70. }