Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes layered navigation options being cached using the wrong store id. #9873

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Magento\Framework\App\CacheInterface;
use Magento\Framework\Serialize\Serializer\Json as Serializer;
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;
Expand All @@ -37,9 +37,9 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
private $cache;

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

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

Expand Down Expand Up @@ -299,7 +302,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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use Magento\Eav\Model\Entity\Attribute\Frontend\DefaultFrontend;
use Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory;
use Magento\Framework\Serialize\Serializer\Json as Serializer;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Framework\App\CacheInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
Expand All @@ -31,9 +32,14 @@ class DefaultFrontendTest extends \PHPUnit_Framework_TestCase
private $serializerMock;

/**
* @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeResolverMock;
private $storeManagerMock;

/**
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeMock;

/**
* @var CacheInterface|\PHPUnit_Framework_MockObject_MockObject
Expand Down Expand Up @@ -64,7 +70,9 @@ protected function setUp()
->getMock();
$this->serializerMock = $this->getMockBuilder(Serializer::class)
->getMock();
$this->storeResolverMock = $this->getMockBuilder(StoreResolverInterface::class)
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
->getMockForAbstractClass();
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
->getMockForAbstractClass();
$this->cacheMock = $this->getMockBuilder(CacheInterface::class)
->getMockForAbstractClass();
Expand All @@ -83,7 +91,7 @@ protected function setUp()
[
'_attrBooleanFactory' => $this->booleanFactory,
'cache' => $this->cacheMock,
'storeResolver' => $this->storeResolverMock,
'storeManager' => $this->storeManagerMock,
'serializer' => $this->serializerMock,
'_attribute' => $this->attributeMock,
'cacheTags' => $this->cacheTags
Expand Down Expand Up @@ -188,8 +196,11 @@ public function testGetSelectOptions()
$options = ['option1', 'option2'];
$serializedOptions = "{['option1', 'option2']}";

$this->storeResolverMock->expects($this->once())
->method('getCurrentStoreId')
$this->storeManagerMock->expects($this->once())
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects($this->once())
->method('getId')
->willReturn($storeId);
$this->attributeMock->expects($this->once())
->method('getAttributeCode')
Expand Down