選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

100 行
3.3KB

  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. }