Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

107 rindas
3.6KB

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