Skip to content

Commit

Permalink
Fixes problem with layered navigation options being cached using the …
Browse files Browse the repository at this point in the history
…wrong store id.
  • Loading branch information
hostep committed May 25, 2017
1 parent e1e4617 commit 488be10
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@

use Magento\Framework\App\CacheInterface;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Eav\Model\Cache\Type as CacheType;
use Magento\Eav\Model\Entity\Attribute;

abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\Frontend\FrontendInterface
{
/**
* Default cache tags values
* will be used if no values in the constructor provided
* @var array
*/
private static $defaultCacheTags = [CacheType::CACHE_TAG, Attribute::CACHE_TAG];

/**
* @var CacheInterface
*/
private $cache;

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @var array
Expand All @@ -51,21 +59,21 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
* @param CacheInterface $cache
* @param StoreResolverInterface $storeResolver
* @param array $cacheTags
* @param StoreManagerInterface $storeManager
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory,
CacheInterface $cache = null,
StoreResolverInterface $storeResolver = null,
array $cacheTags = [
CacheType::CACHE_TAG,
Attribute::CACHE_TAG,
]
array $cacheTags = null,
StoreManagerInterface $storeManager = null
) {
$this->_attrBooleanFactory = $attrBooleanFactory;
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
$this->storeResolver = $storeResolver ?: ObjectManager::getInstance()->get(StoreResolverInterface::class);
$this->cacheTags = $cacheTags;
$this->cacheTags = $cacheTags ?: self::$defaultCacheTags;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand Down Expand Up @@ -252,7 +260,7 @@ public function getSelectOptions()
{
$cacheKey = 'attribute-navigation-option-' .
$this->getAttribute()->getAttributeCode() . '-' .
$this->storeResolver->getCurrentStoreId();
$this->storeManager->getStore()->getId();
$optionString = $this->cache->load($cacheKey);
if (false === $optionString) {
$options = $this->getAttribute()->getSource()->getAllOptions();
Expand Down

0 comments on commit 488be10

Please sign in to comment.