Skip to content

Commit 488be10

Browse files
committed
Fixes problem with layered navigation options being cached using the wrong store id.
1 parent e1e4617 commit 488be10

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@
1313

1414
use Magento\Framework\App\CacheInterface;
1515
use Magento\Store\Api\StoreResolverInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
1617
use Magento\Framework\App\ObjectManager;
1718
use Magento\Eav\Model\Cache\Type as CacheType;
1819
use Magento\Eav\Model\Entity\Attribute;
1920

2021
abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\Frontend\FrontendInterface
2122
{
23+
/**
24+
* Default cache tags values
25+
* will be used if no values in the constructor provided
26+
* @var array
27+
*/
28+
private static $defaultCacheTags = [CacheType::CACHE_TAG, Attribute::CACHE_TAG];
29+
2230
/**
2331
* @var CacheInterface
2432
*/
2533
private $cache;
2634

2735
/**
28-
* @var StoreResolverInterface
36+
* @var StoreManagerInterface
2937
*/
30-
private $storeResolver;
38+
private $storeManager;
3139

3240
/**
3341
* @var array
@@ -51,21 +59,21 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
5159
* @param CacheInterface $cache
5260
* @param StoreResolverInterface $storeResolver
5361
* @param array $cacheTags
62+
* @param StoreManagerInterface $storeManager
5463
* @codeCoverageIgnore
64+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5565
*/
5666
public function __construct(
5767
\Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory,
5868
CacheInterface $cache = null,
5969
StoreResolverInterface $storeResolver = null,
60-
array $cacheTags = [
61-
CacheType::CACHE_TAG,
62-
Attribute::CACHE_TAG,
63-
]
70+
array $cacheTags = null,
71+
StoreManagerInterface $storeManager = null
6472
) {
6573
$this->_attrBooleanFactory = $attrBooleanFactory;
6674
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
67-
$this->storeResolver = $storeResolver ?: ObjectManager::getInstance()->get(StoreResolverInterface::class);
68-
$this->cacheTags = $cacheTags;
75+
$this->cacheTags = $cacheTags ?: self::$defaultCacheTags;
76+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6977
}
7078

7179
/**
@@ -252,7 +260,7 @@ public function getSelectOptions()
252260
{
253261
$cacheKey = 'attribute-navigation-option-' .
254262
$this->getAttribute()->getAttributeCode() . '-' .
255-
$this->storeResolver->getCurrentStoreId();
263+
$this->storeManager->getStore()->getId();
256264
$optionString = $this->cache->load($cacheKey);
257265
if (false === $optionString) {
258266
$options = $this->getAttribute()->getSource()->getAllOptions();

0 commit comments

Comments
 (0)