diff --git a/src/Elcodi/Store/ProductBundle/Resources/config/services.yml b/src/Elcodi/Store/ProductBundle/Resources/config/services.yml index fe3fc68f..92148d57 100644 --- a/src/Elcodi/Store/ProductBundle/Resources/config/services.yml +++ b/src/Elcodi/Store/ProductBundle/Resources/config/services.yml @@ -11,6 +11,7 @@ services: category_tree_service: @elcodi.provider.category_tree load_only_categories_with_products: %elcodi.core.product.load_only_categories_with_products% key: %elcodi.core.product.cache_key% + locale: @elcodi.locale calls: - [setCache, [@doctrine_cache.providers.elcodi_categories]] - [setEncoder, [@elcodi.json_encoder]] diff --git a/src/Elcodi/Store/ProductBundle/Services/StoreCategoryTree.php b/src/Elcodi/Store/ProductBundle/Services/StoreCategoryTree.php index f560e3d1..c0b75873 100644 --- a/src/Elcodi/Store/ProductBundle/Services/StoreCategoryTree.php +++ b/src/Elcodi/Store/ProductBundle/Services/StoreCategoryTree.php @@ -18,6 +18,7 @@ namespace Elcodi\Store\ProductBundle\Services; use Elcodi\Component\Core\Wrapper\Abstracts\AbstractCacheWrapper; +use Elcodi\Component\Language\Entity\Interfaces\LocaleInterface; use Elcodi\Component\Product\Entity\Category; use Elcodi\Component\Product\Services\CategoryTree; @@ -51,21 +52,31 @@ class StoreCategoryTree extends AbstractCacheWrapper */ private $categoryTreeService; + /** + * @var LocaleInterface + * + * Locale in which the categories are stored + */ + protected $locale; + /** * Construct method * - * @param CategoryTree $categoryTreeService The category tree service - * @param boolean $loadOnlyCategoriesWithProducts Load only categories with products - * @param string $key Key where to store info + * @param CategoryTree $categoryTreeService The category tree service + * @param boolean $loadOnlyCategoriesWithProducts Load only categories with products + * @param string $key Key where to store info + * @param LocaleInterface $locale Locale of the categories */ public function __construct( CategoryTree $categoryTreeService, $loadOnlyCategoriesWithProducts, - $key + $key, + LocaleInterface $locale ) { $this->categoryTreeService = $categoryTreeService; $this->loadOnlyCategoriesWithProducts = $loadOnlyCategoriesWithProducts; $this->key = $key; + $this->locale = $locale; } /** @@ -120,7 +131,7 @@ public function reload() { $this ->cache - ->delete($this->key); + ->delete($this->getKey()); $this->storeCategoryTree = null; @@ -139,7 +150,7 @@ protected function loadCategoryTreeFromCache() ->decode( $this ->cache - ->fetch($this->key) + ->fetch($this->getKey()) ); } @@ -168,7 +179,7 @@ protected function saveCategoryTreeIntoCache($categoryTree) $this ->cache ->save( - $this->key, + $this->getKey(), $this->encoder->encode($categoryTree) ); @@ -248,4 +259,12 @@ protected function isCategoryEnabled(Category $category) 0 > ($category->getProducts()) ); } + + /** + * Get current key + */ + protected function getKey() + { + return "{$this->key}_{$this->locale->getIso()}"; + } }