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 regression bug introduced in Magento 2.1.6 where the layered navigation options are sometimes being cached using the wrong store id. #9704

Merged
merged 1 commit into from
Jun 7, 2017
Merged
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,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
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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();
Expand Down