@@ -61,6 +61,15 @@ abstract class ProductCategory extends AbstractDocumentEntity implements TreeInt | |||
return $this; | |||
} | |||
public function getParentCategory() | |||
{ | |||
if($this->getParent()) { | |||
return $this->getParent() ; | |||
} | |||
return $this ; | |||
} | |||
/** | |||
* @return Collection|self[] | |||
*/ |
@@ -358,8 +358,6 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
},false) ; | |||
} | |||
public function isPropertyNoveltyOnline(): ?bool | |||
{ | |||
if($this->getPropertyNoveltyExpirationDate()) { | |||
@@ -368,10 +366,8 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
return true ; | |||
} | |||
} | |||
else { | |||
return false ; | |||
} | |||
return false ; | |||
} | |||
public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface |
@@ -30,21 +30,18 @@ class ProductCategoryRepository extends BaseRepository implements DefaultReposit | |||
public function findAllParents() | |||
{ | |||
return $this->findByMerchantQuery() | |||
$query = $this->findByMerchantQuery() | |||
->andWhere('e.parent is NULL') | |||
->andWhere('e.status >= 0') | |||
->orderBy('e.position', 'ASC') | |||
->getQuery() | |||
->getResult(); | |||
->orderBy('e.position', 'ASC') ; | |||
return $query->getQuery()->getResult(); | |||
} | |||
public function findAllByParent($parentCategory) | |||
{ | |||
//$query = $this->findByMerchantQuery($this->globalParam->getCurrentMerchant()) ; | |||
$query = $this->createQueryBuilder('e') ; | |||
$query->andWhere('e.parent = :idParentCategory') | |||
->setParameter('idParentCategory', $parentCategory->getId()); | |||
return $query->getQuery()->getResult() ; | |||
} | |||
} |
@@ -18,4 +18,46 @@ class ProductFamilyRepository extends BaseRepository implements DefaultRepositor | |||
return ProductFamilyInterface::class; | |||
} | |||
public function findNovelties() | |||
{ | |||
$query = $this->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; | |||
} | |||
} |