findByMerchantQuery() ; $query->andWhere(':now <= e.propertyNoveltyExpirationDate') ->setParameter('now', new \DateTime()) ; return $query->getQuery()->getResult() ; } public function findNoveltiesByParentCategories() { return $this->_productsByParentCategories($this->findNovelties()) ; } public function findOrganics() { $query = $this->findByMerchantQuery() ; $query->andWhere('e.propertyOrganicLabel IS NOT NULL'); return $query->getQuery()->getResult() ; } public function findOrganicsByParentCategories() { return $this->_productsByParentCategories($this->findOrganics()) ; } public function _productsByParentCategories($products) { $categoriesArray = [] ; foreach($products as $product) { $productCategories = $product->getProductCategories() ; $category = $productCategories[0]->getParentCategory() ; if(!isset($categoriesArray[$category->getId()])) { $categoriesArray[$category->getId()] = [ 'category' => $category, 'products' => [] ] ; } $categoriesArray[$category->getId()]['products'][] = $product ; } return $categoriesArray; } }