From 488be103b906d16c6f1e545ebebd855e55118e7a Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Fri, 19 May 2017 20:21:22 +0200 Subject: [PATCH] Fixes problem with layered navigation options being cached using the wrong store id. --- .../Attribute/Frontend/AbstractFrontend.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php b/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php index 5979526457cf7..2a4f08da3a2ea 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php @@ -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 @@ -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); } /** @@ -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();