Skip to content

Commit 9aec90e

Browse files
committed
Fixes layered navigation options being cached using the wrong store id.
1 parent 2bc3bb0 commit 9aec90e

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Magento\Framework\App\CacheInterface;
1515
use Magento\Framework\Serialize\Serializer\Json as Serializer;
16-
use Magento\Store\Api\StoreResolverInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
1717
use Magento\Framework\App\ObjectManager;
1818
use Magento\Eav\Model\Cache\Type as CacheType;
1919
use Magento\Eav\Model\Entity\Attribute;
@@ -37,9 +37,9 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
3737
private $cache;
3838

3939
/**
40-
* @var StoreResolverInterface
40+
* @var StoreManagerInterface
4141
*/
42-
private $storeResolver;
42+
private $storeManager;
4343

4444
/**
4545
* @var Serializer
@@ -66,22 +66,25 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
6666
/**
6767
* @param BooleanFactory $attrBooleanFactory
6868
* @param CacheInterface $cache
69-
* @param StoreResolverInterface $storeResolver
69+
* @param $storeResolver @deprecated
7070
* @param array $cacheTags
71+
* @param StoreManagerInterface $storeManager
7172
* @param Serializer $serializer
7273
* @codeCoverageIgnore
74+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7375
*/
7476
public function __construct(
7577
BooleanFactory $attrBooleanFactory,
7678
CacheInterface $cache = null,
77-
StoreResolverInterface $storeResolver = null,
79+
$storeResolver = null,
7880
array $cacheTags = null,
81+
StoreManagerInterface $storeManager = null,
7982
Serializer $serializer = null
8083
) {
8184
$this->_attrBooleanFactory = $attrBooleanFactory;
8285
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
83-
$this->storeResolver = $storeResolver ?: ObjectManager::getInstance()->get(StoreResolverInterface::class);
8486
$this->cacheTags = $cacheTags ?: self::$defaultCacheTags;
87+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
8588
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Serializer::class);
8689
}
8790

@@ -299,7 +302,7 @@ public function getSelectOptions()
299302
{
300303
$cacheKey = 'attribute-navigation-option-' .
301304
$this->getAttribute()->getAttributeCode() . '-' .
302-
$this->storeResolver->getCurrentStoreId();
305+
$this->storeManager->getStore()->getId();
303306
$optionString = $this->cache->load($cacheKey);
304307
if (false === $optionString) {
305308
$options = $this->getAttribute()->getSource()->getAllOptions();

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use Magento\Eav\Model\Entity\Attribute\Frontend\DefaultFrontend;
99
use Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory;
1010
use Magento\Framework\Serialize\Serializer\Json as Serializer;
11-
use Magento\Store\Api\StoreResolverInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Store\Api\Data\StoreInterface;
1213
use Magento\Framework\App\CacheInterface;
1314
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1415
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
@@ -31,9 +32,14 @@ class DefaultFrontendTest extends \PHPUnit_Framework_TestCase
3132
private $serializerMock;
3233

3334
/**
34-
* @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
35+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
3536
*/
36-
private $storeResolverMock;
37+
private $storeManagerMock;
38+
39+
/**
40+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $storeMock;
3743

3844
/**
3945
* @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -64,7 +70,9 @@ protected function setUp()
6470
->getMock();
6571
$this->serializerMock = $this->getMockBuilder(Serializer::class)
6672
->getMock();
67-
$this->storeResolverMock = $this->getMockBuilder(StoreResolverInterface::class)
73+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
74+
->getMockForAbstractClass();
75+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
6876
->getMockForAbstractClass();
6977
$this->cacheMock = $this->getMockBuilder(CacheInterface::class)
7078
->getMockForAbstractClass();
@@ -83,7 +91,7 @@ protected function setUp()
8391
[
8492
'_attrBooleanFactory' => $this->booleanFactory,
8593
'cache' => $this->cacheMock,
86-
'storeResolver' => $this->storeResolverMock,
94+
'storeManager' => $this->storeManagerMock,
8795
'serializer' => $this->serializerMock,
8896
'_attribute' => $this->attributeMock,
8997
'cacheTags' => $this->cacheTags
@@ -188,8 +196,11 @@ public function testGetSelectOptions()
188196
$options = ['option1', 'option2'];
189197
$serializedOptions = "{['option1', 'option2']}";
190198

191-
$this->storeResolverMock->expects($this->once())
192-
->method('getCurrentStoreId')
199+
$this->storeManagerMock->expects($this->once())
200+
->method('getStore')
201+
->willReturn($this->storeMock);
202+
$this->storeMock->expects($this->once())
203+
->method('getId')
193204
->willReturn($storeId);
194205
$this->attributeMock->expects($this->once())
195206
->method('getAttributeCode')

0 commit comments

Comments
 (0)