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

ProductFamilyRepository.php 2.4KB

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