Skip to content

Commit 2d8bb99

Browse files
author
Oleksii Korshenko
authored
MAGETWO-69543: Fixes regression bug introduced in Magento 2.1.6 where the layered navigation options are sometimes being cached using the wrong store id. #9704
2 parents 5d87eb1 + a167e20 commit 2d8bb99

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,29 @@
1212
namespace Magento\Eav\Model\Entity\Attribute\Frontend;
1313

1414
use Magento\Framework\App\CacheInterface;
15-
use Magento\Store\Api\StoreResolverInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
1616
use Magento\Framework\App\ObjectManager;
1717
use Magento\Eav\Model\Cache\Type as CacheType;
1818
use Magento\Eav\Model\Entity\Attribute;
1919

2020
abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\Frontend\FrontendInterface
2121
{
22+
/**
23+
* Default cache tags values
24+
* will be used if no values in the constructor provided
25+
* @var array
26+
*/
27+
private static $defaultCacheTags = [CacheType::CACHE_TAG, Attribute::CACHE_TAG];
28+
2229
/**
2330
* @var CacheInterface
2431
*/
2532
private $cache;
2633

2734
/**
28-
* @var StoreResolverInterface
35+
* @var StoreManagerInterface
2936
*/
30-
private $storeResolver;
37+
private $storeManager;
3138

3239
/**
3340
* @var array
@@ -49,23 +56,23 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
4956
/**
5057
* @param \Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory
5158
* @param CacheInterface $cache
52-
* @param StoreResolverInterface $storeResolver
59+
* @param $storeResolver @deprecated
5360
* @param array $cacheTags
61+
* @param StoreManagerInterface $storeManager
5462
* @codeCoverageIgnore
63+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5564
*/
5665
public function __construct(
5766
\Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory,
5867
CacheInterface $cache = null,
59-
StoreResolverInterface $storeResolver = null,
60-
array $cacheTags = [
61-
CacheType::CACHE_TAG,
62-
Attribute::CACHE_TAG,
63-
]
68+
$storeResolver = null,
69+
array $cacheTags = null,
70+
StoreManagerInterface $storeManager = null
6471
) {
6572
$this->_attrBooleanFactory = $attrBooleanFactory;
6673
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
67-
$this->storeResolver = $storeResolver ?: ObjectManager::getInstance()->get(StoreResolverInterface::class);
68-
$this->cacheTags = $cacheTags;
74+
$this->cacheTags = $cacheTags ?: self::$defaultCacheTags;
75+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6976
}
7077

7178
/**
@@ -252,7 +259,7 @@ public function getSelectOptions()
252259
{
253260
$cacheKey = 'attribute-navigation-option-' .
254261
$this->getAttribute()->getAttributeCode() . '-' .
255-
$this->storeResolver->getCurrentStoreId();
262+
$this->storeManager->getStore()->getId();
256263
$optionString = $this->cache->load($cacheKey);
257264
if (false === $optionString) {
258265
$options = $this->getAttribute()->getSource()->getAllOptions();

0 commit comments

Comments
 (0)