Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ProductFamilyRepository.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ProductFamilyInterface;
  5. /**
  6. * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
  7. * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
  8. * @method ProductFamilyInterface[] findAll()
  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 findNovelties()
  18. {
  19. $query = $this->findByMerchantQuery() ;
  20. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  21. ->setParameter('now', new \DateTime()) ;
  22. return $query->getQuery()->getResult() ;
  23. }
  24. public function findNoveltiesByParentCategories()
  25. {
  26. return $this->_productsByParentCategories($this->findNovelties()) ;
  27. }
  28. public function findOrganics()
  29. {
  30. $query = $this->findByMerchantQuery() ;
  31. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  32. return $query->getQuery()->getResult() ;
  33. }
  34. public function findOrganicsByParentCategories()
  35. {
  36. return $this->_productsByParentCategories($this->findOrganics()) ;
  37. }
  38. public function _productsByParentCategories($products)
  39. {
  40. $categoriesArray = [] ;
  41. foreach($products as $product) {
  42. $productCategories = $product->getProductCategories() ;
  43. $category = $productCategories[0]->getParentCategory() ;
  44. if(!isset($categoriesArray[$category->getId()])) {
  45. $categoriesArray[$category->getId()] = [
  46. 'category' => $category,
  47. 'products' => []
  48. ] ;
  49. }
  50. $categoriesArray[$category->getId()]['products'][] = $product ;
  51. }
  52. return $categoriesArray;
  53. }
  54. public function findByTerms($terms, $maxResults = false)
  55. {
  56. $query = $this->findByMerchantQuery() ;
  57. $query->andWhere('e.title LIKE :terms');
  58. $query->setParameter('terms', '%'.$terms.'%') ;
  59. if($maxResults) {
  60. $query->setMaxResults($maxResults) ;
  61. }
  62. return $query->getQuery()->getResult() ;
  63. }
  64. }