Skip to content

Commit 438b0f0

Browse files
author
Roman Lytvynenko
committed
MC-18094: Full page cache issue with non-default store view
1 parent d396adc commit 438b0f0

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
namespace Magento\Store\App\Action\Plugin;
88

9+
use Magento\Framework\App\Action\AbstractAction;
910
use Magento\Framework\App\Http\Context as HttpContext;
11+
use Magento\Framework\App\RequestInterface;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Exception\NotFoundException;
1214
use Magento\Store\Api\Data\StoreInterface;
1315
use Magento\Store\Api\StoreCookieManagerInterface;
14-
use Magento\Store\Model\Store;
1516
use Magento\Store\Model\StoreManagerInterface;
16-
use Magento\Framework\App\Action\AbstractAction;
17-
use Magento\Framework\App\RequestInterface;
1817

1918
/**
2019
* Class ContextPlugin
@@ -132,15 +131,11 @@ private function processInvalidStoreRequested(
132131
*/
133132
private function updateContext(StoreInterface $store)
134133
{
135-
if (!$store->getConfig(Store::XML_PATH_STORE_IN_URL) ||
136-
$store->getCode() == $this->storeManager->getDefaultStoreView()->getCode()
137-
) {
138-
$this->httpContext->setValue(
139-
StoreManagerInterface::CONTEXT_STORE,
140-
$store->getCode(),
141-
$this->storeManager->getDefaultStoreView()->getCode()
142-
);
143-
}
134+
$this->httpContext->setValue(
135+
StoreManagerInterface::CONTEXT_STORE,
136+
$store->getCode(),
137+
$store->isUseStoreInUrl() ? $store->getCode() : $this->storeManager->getDefaultStoreView()->getCode()
138+
);
144139

145140
/** @var StoreInterface $defaultStore */
146141
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ class ContextNonDefaultStoreDirectLinkTest extends TestCase
3535
* Test for full page cache hits from new http clients if store context was specified in the URL
3636
*
3737
* @dataProvider cacheHitOnDirectLinkToNonDefaultStoreView
38-
* @param $customStore
39-
* @param $defaultStore
40-
* @param $setValueNumberOfTimes
41-
* @param $xmlPathStoreInUrl
38+
* @param string $customStore
39+
* @param string $defaultStore
40+
* @param string $expectedDefaultStore
41+
* @param bool $useStoreInUrl
4242
* @return void
4343
*/
4444
public function testCacheHitOnDirectLinkToNonDefaultStoreView(
45-
$customStore,
46-
$defaultStore,
47-
$setValueNumberOfTimes,
48-
$xmlPathStoreInUrl
45+
string $customStore,
46+
string $defaultStore,
47+
string $expectedDefaultStore,
48+
bool $useStoreInUrl
4949
) {
5050
$sessionMock = $this->createPartialMock(Generic::class, ['getCurrencyCode']);
5151
$httpContextMock = $this->createMock(HttpContext::class);
@@ -89,14 +89,12 @@ public function testCacheHitOnDirectLinkToNonDefaultStoreView(
8989
->method('getDefaultCurrencyCode')
9090
->willReturn(self::CURRENCY_CURRENT_STORE);
9191

92-
$currentStoreMock->expects($this->any())
93-
->method('getConfig')
94-
->willReturn($xmlPathStoreInUrl);
95-
9692
$currentStoreMock->expects($this->any())
9793
->method('getCode')
9894
->willReturn($customStore);
9995

96+
$currentStoreMock->method('isUseStoreInUrl')->willReturn($useStoreInUrl);
97+
10098
$storeManager->expects($this->any())
10199
->method('getWebsite')
102100
->willReturn($websiteMock);
@@ -126,8 +124,11 @@ public function testCacheHitOnDirectLinkToNonDefaultStoreView(
126124
->method('getCurrencyCode')
127125
->willReturn(self::CURRENCY_SESSION);
128126

129-
$httpContextMock->expects($this->exactly($setValueNumberOfTimes))
130-
->method('setValue');
127+
$httpContextMock->expects($this->at(1))->method(
128+
'setValue'
129+
)->with(StoreManagerInterface::CONTEXT_STORE, $customStore, $expectedDefaultStore);
130+
131+
$httpContextMock->expects($this->at(2))->method('setValue');
131132

132133
$plugin->beforeDispatch(
133134
$subjectMock,
@@ -141,20 +142,20 @@ public function cacheHitOnDirectLinkToNonDefaultStoreView()
141142
[
142143
'custom_store',
143144
'default',
144-
1,
145-
1
145+
'custom_store',
146+
true,
146147
],
147148
[
149+
'custom_store',
148150
'default',
149151
'default',
150-
2,
151-
0
152+
false,
152153
],
153154
[
154155
'default',
155156
'default',
156-
2,
157-
1
157+
'default',
158+
true,
158159
],
159160
];
160161
}

0 commit comments

Comments
 (0)