|
|
@@ -11,6 +11,8 @@ use Lc\CaracoleBundle\Solver\Price\PriceSolver; |
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
|
use Lc\CaracoleBundle\Repository\AbstractStore; |
|
|
|
use Lc\SovBundle\Repository\RepositoryQueryInterface; |
|
|
|
use Symfony\Contracts\Cache\CacheInterface; |
|
|
|
use Symfony\Contracts\Cache\ItemInterface; |
|
|
|
|
|
|
|
class ProductFamilyStore extends AbstractStore |
|
|
|
{ |
|
|
@@ -19,13 +21,16 @@ class ProductFamilyStore extends AbstractStore |
|
|
|
|
|
|
|
protected ProductFamilyRepositoryQuery $query; |
|
|
|
protected PriceSolver $priceSolver; |
|
|
|
protected CacheInterface $cache; |
|
|
|
|
|
|
|
public function __construct( |
|
|
|
ProductFamilyRepositoryQuery $query, |
|
|
|
PriceSolver $priceSolver |
|
|
|
PriceSolver $priceSolver, |
|
|
|
CacheInterface $cache |
|
|
|
) { |
|
|
|
$this->query = $query; |
|
|
|
$this->priceSolver = $priceSolver; |
|
|
|
$this->cache = $cache; |
|
|
|
} |
|
|
|
|
|
|
|
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface |
|
|
@@ -116,6 +121,25 @@ class ProductFamilyStore extends AbstractStore |
|
|
|
return $this->getWithReductions($results, $user, false, $organizeByParentCategory); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCachedNovelty($user = null, $organizeByParentCategory = true, $query = null): array |
|
|
|
{ |
|
|
|
$productFamilyStore = $this; |
|
|
|
return $this->cache->get($this->getCacheKeyNovelty(), function (ItemInterface $item) use ($productFamilyStore, $user, $organizeByParentCategory, $query) { |
|
|
|
$item->expiresAfter(3600); |
|
|
|
return $productFamilyStore->getNovelty($user, $organizeByParentCategory, $query); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteCacheNovelty(): void |
|
|
|
{ |
|
|
|
$this->cache->delete($this->getCacheKeyNovelty()); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCacheKeyNovelty() |
|
|
|
{ |
|
|
|
return 'products_novelty_'.$this->section->getId(); |
|
|
|
} |
|
|
|
|
|
|
|
// getProductFamiliesOrganics |
|
|
|
public function getOrganic($user = null, $organizeByParentCategory = true, $query = null) |
|
|
|
{ |
|
|
@@ -134,6 +158,31 @@ class ProductFamilyStore extends AbstractStore |
|
|
|
return $this->getWithReductions($this->getOnline($query), $user, false, $organizeByParentCategory, true); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCachedDiscount($user = null, $organizeByParentCategory = true, $query = null): array |
|
|
|
{ |
|
|
|
$productFamilyStore = $this; |
|
|
|
|
|
|
|
return $this->cache->get($this->getCacheKeyDiscount(), function (ItemInterface $item) use ($productFamilyStore, $user, $organizeByParentCategory, $query) { |
|
|
|
$item->expiresAfter(3600); |
|
|
|
return $productFamilyStore->getDiscount($user, $organizeByParentCategory, $query); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteCacheDiscount(): void |
|
|
|
{ |
|
|
|
$this->cache->delete($this->getCacheKeyDiscount()); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCacheKeyDiscount() |
|
|
|
{ |
|
|
|
return 'products_discount_'.$this->section->getId(); |
|
|
|
} |
|
|
|
|
|
|
|
public function loadAllDatas(ProductFamilyInterface $productFamily) |
|
|
|
{ |
|
|
|
$productFamily->getProductFamilySectionProperties()->toArray(); |
|
|
|
} |
|
|
|
|
|
|
|
// getProductFamiliesFavorites |
|
|
|
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null) |
|
|
|
{ |
|
|
@@ -227,6 +276,10 @@ class ProductFamilyStore extends AbstractStore |
|
|
|
|
|
|
|
$productFamiliesToReturn = array(); |
|
|
|
foreach ($productFamilies as $productFamily) { |
|
|
|
|
|
|
|
// Cache : chargement de toutes les données manquantes (fetch eager ne fonctionne pas) |
|
|
|
$this->loadAllDatas($productFamily); |
|
|
|
|
|
|
|
foreach ($reductionCatalogs as $reductionCatalog) { |
|
|
|
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false; |
|
|
|
|