|
|
|
|
|
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\CaracoleBundle\Repository\AbstractStore; |
|
|
use Lc\CaracoleBundle\Repository\AbstractStore; |
|
|
use Lc\SovBundle\Repository\RepositoryQueryInterface; |
|
|
use Lc\SovBundle\Repository\RepositoryQueryInterface; |
|
|
|
|
|
use Symfony\Contracts\Cache\CacheInterface; |
|
|
|
|
|
use Symfony\Contracts\Cache\ItemInterface; |
|
|
|
|
|
|
|
|
class ProductFamilyStore extends AbstractStore |
|
|
class ProductFamilyStore extends AbstractStore |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected ProductFamilyRepositoryQuery $query; |
|
|
protected ProductFamilyRepositoryQuery $query; |
|
|
protected PriceSolver $priceSolver; |
|
|
protected PriceSolver $priceSolver; |
|
|
|
|
|
protected CacheInterface $cache; |
|
|
|
|
|
|
|
|
public function __construct( |
|
|
public function __construct( |
|
|
ProductFamilyRepositoryQuery $query, |
|
|
ProductFamilyRepositoryQuery $query, |
|
|
PriceSolver $priceSolver |
|
|
|
|
|
|
|
|
PriceSolver $priceSolver, |
|
|
|
|
|
CacheInterface $cache |
|
|
) { |
|
|
) { |
|
|
$this->query = $query; |
|
|
$this->query = $query; |
|
|
$this->priceSolver = $priceSolver; |
|
|
$this->priceSolver = $priceSolver; |
|
|
|
|
|
$this->cache = $cache; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface |
|
|
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface |
|
|
|
|
|
|
|
|
return $this->getWithReductions($results, $user, false, $organizeByParentCategory); |
|
|
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 |
|
|
// getProductFamiliesOrganics |
|
|
public function getOrganic($user = null, $organizeByParentCategory = true, $query = null) |
|
|
public function getOrganic($user = null, $organizeByParentCategory = true, $query = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
return $this->getWithReductions($this->getOnline($query), $user, false, $organizeByParentCategory, true); |
|
|
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 |
|
|
// getProductFamiliesFavorites |
|
|
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null) |
|
|
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$productFamiliesToReturn = array(); |
|
|
$productFamiliesToReturn = array(); |
|
|
foreach ($productFamilies as $productFamily) { |
|
|
foreach ($productFamilies as $productFamily) { |
|
|
|
|
|
|
|
|
|
|
|
// Cache : chargement de toutes les données manquantes (fetch eager ne fonctionne pas) |
|
|
|
|
|
$this->loadAllDatas($productFamily); |
|
|
|
|
|
|
|
|
foreach ($reductionCatalogs as $reductionCatalog) { |
|
|
foreach ($reductionCatalogs as $reductionCatalog) { |
|
|
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false; |
|
|
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false; |
|
|
|
|
|
|