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.

64 lines
2.4KB

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