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.

ProductFamilyRepository.php 4.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 getProductFamiliesByCategory($category){
  19. $expr = $this->_em->getExpressionBuilder();
  20. $query = $this->findByMerchantQuery() ;
  21. /* $query->select(array('e as product', 'reductionCatalog as reduction'));
  22. $query->from(ReductionCatalogInterface::class, 'reductionCatalog');*/
  23. $query->andWhere(':category MEMBER OF e.productCategories');
  24. $query->andWhere('e.status = 1');
  25. /* /* $query->andWhere($query->expr()->orX(
  26. $query->expr()->eq('reductionCatalog', 'null'),
  27. $query->expr()->eq( 'reductionCatalog.status = 1 AND (
  28. :user MEMBER OF reductionCatalog.users OR reductionCatalog.users is empty ) AND
  29. (:groupUser MEMBER OF reductionCatalog.groupUsers OR reductionCatalog.groupUsers is empty ) AND
  30. (e MEMBER OF reductionCatalog.productFamilies OR reductionCatalog.productFamilies is empty')
  31. ));
  32. $query
  33. ->andWhere('reductionCatalog.status = 1')
  34. ->andWhere(':user MEMBER OF reductionCatalog.users OR reductionCatalog.users is empty')
  35. ->andWhere(':groupUser MEMBER OF reductionCatalog.groupUsers OR reductionCatalog.groupUsers is empty')
  36. ->andWhere('e MEMBER OF reductionCatalog.productFamilies OR reductionCatalog.productFamilies is empty')
  37. //->andWhere(':category MEMBER OF reductionCatalog.productCategories OR reductionCatalog.productCategories is empty')
  38. //->andWhere('e.supplier MEMBER OF reductionCatalog.suppliers OR reductionCatalog.suppliers is empty')
  39. ->setParameter('user', $user)
  40. ->setParameter('groupUser', $user->getGroupUsers()
  41. );*/
  42. $query->setParameter('category', $category->getId());
  43. return $query->getQuery()->getResult() ;
  44. }
  45. public function getProductFamiliesNovelties(){
  46. $query = $this->findByMerchantQuery() ;
  47. $query->andWhere('e.status = 1');
  48. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  49. ->setParameter('now', new \DateTime()) ;
  50. return $query->getQuery()->getResult() ;
  51. }
  52. public function getProductFamiliesLargeVolumes(){
  53. $query = $this->findByMerchantQuery() ;
  54. $query->andWhere('e.status = 1');
  55. $query->andWhere('e.propertyLargeVolume = 1');
  56. return $query->getQuery()->getResult() ;
  57. }
  58. public function getProductFamiliesOrganics(){
  59. $query = $this->findByMerchantQuery() ;
  60. $query->andWhere('e.status = 1');
  61. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  62. return $query->getQuery()->getResult() ;
  63. }
  64. public function findByTerms($terms, $maxResults = false)
  65. {
  66. $query = $this->findByMerchantQuery() ;
  67. $query->andWhere('e.status = 1');
  68. $query->andWhere('e.title LIKE :terms');
  69. $query->setParameter(':terms', '%'.$terms.'%') ;
  70. if($maxResults) {
  71. $query->setMaxResults($maxResults) ;
  72. }
  73. return $query->getQuery()->getResult() ;
  74. }
  75. }