Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Commit

Permalink
multilanguage support for category tree
Browse files Browse the repository at this point in the history
  • Loading branch information
xphere committed Jul 16, 2015
1 parent 5d59995 commit 98df7d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
33 changes: 26 additions & 7 deletions src/Elcodi/Store/ProductBundle/Services/StoreCategoryTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -120,7 +131,7 @@ public function reload()
{
$this
->cache
->delete($this->key);
->delete($this->getKey());

$this->storeCategoryTree = null;

Expand All @@ -139,7 +150,7 @@ protected function loadCategoryTreeFromCache()
->decode(
$this
->cache
->fetch($this->key)
->fetch($this->getKey())
);
}

Expand Down Expand Up @@ -168,7 +179,7 @@ protected function saveCategoryTreeIntoCache($categoryTree)
$this
->cache
->save(
$this->key,
$this->getKey(),
$this->encoder->encode($categoryTree)
);

Expand Down Expand Up @@ -248,4 +259,12 @@ protected function isCategoryEnabled(Category $category)
0 > ($category->getProducts())
);
}

/**
* Get current key
*/
protected function getKey()
{
return "{$this->key}_{$this->locale->getIso()}";
}
}

0 comments on commit 98df7d0

Please sign in to comment.