Skip to content

Commit 39dd6c8

Browse files
committed
MC-19712: Full page cache issue with multiple stores
1 parent 50acd4f commit 39dd6c8

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

app/code/Magento/Store/App/Action/Plugin/Context.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\Exception\NoSuchEntityException;
1313
use Magento\Framework\Exception\NotFoundException;
14+
use Magento\Framework\Session\SessionManagerInterface;
1415
use Magento\Store\Api\Data\StoreInterface;
1516
use Magento\Store\Api\StoreCookieManagerInterface;
1617
use Magento\Store\Model\ScopeInterface;
@@ -23,17 +24,17 @@
2324
class Context
2425
{
2526
/**
26-
* @var \Magento\Framework\Session\SessionManagerInterface
27+
* @var SessionManagerInterface
2728
*/
2829
protected $session;
2930

3031
/**
31-
* @var \Magento\Framework\App\Http\Context
32+
* @var HttpContext
3233
*/
3334
protected $httpContext;
3435

3536
/**
36-
* @var \Magento\Store\Model\StoreManagerInterface
37+
* @var StoreManagerInterface
3738
*/
3839
protected $storeManager;
3940

@@ -43,15 +44,15 @@ class Context
4344
protected $storeCookieManager;
4445

4546
/**
46-
* @param \Magento\Framework\Session\SessionManagerInterface $session
47-
* @param \Magento\Framework\App\Http\Context $httpContext
48-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
47+
* @param SessionManagerInterface $session
48+
* @param HttpContext $httpContext
49+
* @param StoreManagerInterface $storeManager
4950
* @param StoreCookieManagerInterface $storeCookieManager
5051
*/
5152
public function __construct(
52-
\Magento\Framework\Session\SessionManagerInterface $session,
53-
\Magento\Framework\App\Http\Context $httpContext,
54-
\Magento\Store\Model\StoreManagerInterface $storeManager,
53+
SessionManagerInterface $session,
54+
HttpContext $httpContext,
55+
StoreManagerInterface $storeManager,
5556
StoreCookieManagerInterface $storeCookieManager
5657
) {
5758
$this->session = $session;
@@ -80,7 +81,7 @@ public function beforeDispatch(
8081

8182
/** @var string|array|null $storeCode */
8283
$storeCode = $request->getParam(
83-
\Magento\Store\Model\StoreManagerInterface::PARAM_NAME,
84+
StoreManagerInterface::PARAM_NAME,
8485
$this->storeCookieManager->getStoreCodeFromCookie()
8586
);
8687
if (is_array($storeCode)) {
@@ -106,13 +107,13 @@ public function beforeDispatch(
106107
* Take action in case of invalid store requested.
107108
*
108109
* @param RequestInterface $request
109-
* @param \Throwable|null $previousException
110+
* @param NoSuchEntityException|null $previousException
110111
* @return void
111112
* @throws NotFoundException
112113
*/
113114
private function processInvalidStoreRequested(
114115
RequestInterface $request,
115-
\Throwable $previousException = null
116+
NoSuchEntityException $previousException = null
116117
) {
117118
$store = $this->storeManager->getStore();
118119
$this->updateContext($request, $store);
@@ -137,27 +138,25 @@ private function updateContext(RequestInterface $request, StoreInterface $store)
137138
{
138139
switch (true) {
139140
case $store->isUseStoreInUrl():
140-
$defaultStoreCode = $store->getCode();
141+
$defaultStore = $store;
141142
break;
142143
case ScopeInterface::SCOPE_STORE == $request->getServerValue(StoreManager::PARAM_RUN_TYPE):
143144
$defaultStoreCode = $request->getServerValue(StoreManager::PARAM_RUN_CODE);
145+
$defaultStore = $this->storeManager->getStore($defaultStoreCode);
144146
break;
145147
default:
146148
$defaultStoreCode = $this->storeManager->getDefaultStoreView()->getCode();
149+
$defaultStore = $this->storeManager->getStore($defaultStoreCode);
147150
break;
148151
}
149152
$this->httpContext->setValue(
150153
StoreManagerInterface::CONTEXT_STORE,
151154
$store->getCode(),
152-
$defaultStoreCode
155+
$defaultStore->getCode()
153156
);
154-
155-
/** @var StoreInterface $defaultStore */
156-
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
157157
$this->httpContext->setValue(
158158
HttpContext::CONTEXT_CURRENCY,
159-
$this->session->getCurrencyCode()
160-
?: $store->getDefaultCurrencyCode(),
159+
$this->session->getCurrencyCode() ?: $store->getDefaultCurrencyCode(),
161160
$defaultStore->getDefaultCurrencyCode()
162161
);
163162
}

app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextNonDefaultStoreDirectLinkTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public function testCacheHitOnDirectLinkToNonDefaultStoreView(
5353
$storeCookieManager = $this->createMock(StoreCookieManagerInterface::class);
5454
$storeMock = $this->createMock(Store::class);
5555
$currentStoreMock = $this->createMock(Store::class);
56-
$requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
56+
$requestMock = $this->getMockBuilder(RequestInterface::class)
57+
->disableOriginalConstructor()
58+
->setMethods(['getServerValue'])
59+
->getMockForAbstractClass();
5760
$subjectMock = $this->getMockBuilder(AbstractAction::class)
5861
->disableOriginalConstructor()
5962
->getMockForAbstractClass();

app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ protected function setUp()
9393
\Magento\Store\Model\Website::class,
9494
['getDefaultStore', '__wakeup']
9595
);
96-
$this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
96+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
97+
->disableOriginalConstructor()
98+
->setMethods(['getServerValue'])
99+
->getMockForAbstractClass();
97100
$this->subjectMock = $this->getMockBuilder(AbstractAction::class)
98101
->disableOriginalConstructor()
99102
->getMockForAbstractClass();

0 commit comments

Comments
 (0)