Skip to content

Commit 3f528b7

Browse files
author
Novykov Ivan
committed
MDVA-226: Product URL in shared wishlist is returning bad url
1 parent 932193a commit 3f528b7

File tree

3 files changed

+128
-13
lines changed

3 files changed

+128
-13
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Store\App\Action\Plugin;
88

99
use Magento\Framework\App\Http\Context as HttpContext;
10+
use Magento\Framework\Phrase;
1011
use Magento\Store\Api\StoreCookieManagerInterface;
1112
use Magento\Store\Api\StoreResolverInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
@@ -77,12 +78,19 @@ public function aroundDispatch(
7778
/** @var \Magento\Store\Model\Store $defaultStore */
7879
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
7980

80-
$requestedStoreCode = $this->httpRequest->getParam(
81+
$storeCode = $this->httpRequest->getParam(
8182
StoreResolverInterface::PARAM_NAME,
8283
$this->storeCookieManager->getStoreCodeFromCookie()
8384
);
85+
86+
if (is_array($storeCode)) {
87+
if (!isset($storeCode['_data']['code'])) {
88+
throw new \InvalidArgumentException(new Phrase('Invalid store parameter.'));
89+
}
90+
$storeCode = $storeCode['_data']['code'];
91+
}
8492
/** @var \Magento\Store\Model\Store $currentStore */
85-
$currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore;
93+
$currentStore = $storeCode ? $this->storeManager->getStore($storeCode) : $defaultStore;
8694

8795
$this->httpContext->setValue(
8896
StoreManagerInterface::CONTEXT_STORE,

app/code/Magento/Store/Model/StoreResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public function getCurrentStoreId()
8585
list($stores, $defaultStoreId) = $this->getStoresData();
8686

8787
$storeCode = $this->request->getParam(self::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie());
88+
if (is_array($storeCode)) {
89+
if (!isset($storeCode['_data']['code'])) {
90+
throw new \InvalidArgumentException(__('Invalid store parameter.'));
91+
}
92+
$storeCode = $storeCode['_data']['code'];
93+
}
8894
if ($storeCode) {
8995
try {
9096
$store = $this->getRequestedStoreByCode($storeCode);

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

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,34 +159,41 @@ public function setUp()
159159
->will($this->returnValue($this->websiteMock));
160160
$this->storeManager->method('getDefaultStoreView')
161161
->willReturn($this->storeMock);
162-
$this->storeManager->method('getStore')
163-
->willReturn($this->currentStoreMock);
162+
164163
$this->websiteMock->expects($this->once())
165164
->method('getDefaultStore')
166165
->will($this->returnValue($this->storeMock));
166+
167+
$this->storeCookieManager->expects($this->once())
168+
->method('getStoreCodeFromCookie')
169+
->will($this->returnValue('storeCookie'));
170+
$this->currentStoreMock->expects($this->any())
171+
->method('getDefaultCurrencyCode')
172+
->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
173+
}
174+
175+
public function testAroundDispatchCurrencyFromSession()
176+
{
167177
$this->storeMock->expects($this->once())
168178
->method('getDefaultCurrencyCode')
169179
->will($this->returnValue(self::CURRENCY_DEFAULT));
180+
170181
$this->storeMock->expects($this->once())
171182
->method('getCode')
172183
->willReturn('default');
173184
$this->currentStoreMock->expects($this->once())
174185
->method('getCode')
175186
->willReturn('custom_store');
176-
$this->storeCookieManager->expects($this->once())
177-
->method('getStoreCodeFromCookie')
178-
->will($this->returnValue('storeCookie'));
187+
179188
$this->httpRequestMock->expects($this->once())
180189
->method('getParam')
181190
->with($this->equalTo('___store'))
182191
->will($this->returnValue('default'));
183-
$this->currentStoreMock->expects($this->any())
184-
->method('getDefaultCurrencyCode')
185-
->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
186-
}
187192

188-
public function testAroundDispatchCurrencyFromSession()
189-
{
193+
$this->storeManager->method('getStore')
194+
->with('default')
195+
->willReturn($this->currentStoreMock);
196+
190197
$this->sessionMock->expects($this->any())
191198
->method('getCurrencyCode')
192199
->will($this->returnValue(self::CURRENCY_SESSION));
@@ -207,6 +214,26 @@ public function testAroundDispatchCurrencyFromSession()
207214

208215
public function testDispatchCurrentStoreCurrency()
209216
{
217+
$this->storeMock->expects($this->once())
218+
->method('getDefaultCurrencyCode')
219+
->will($this->returnValue(self::CURRENCY_DEFAULT));
220+
221+
$this->storeMock->expects($this->once())
222+
->method('getCode')
223+
->willReturn('default');
224+
$this->currentStoreMock->expects($this->once())
225+
->method('getCode')
226+
->willReturn('custom_store');
227+
228+
$this->httpRequestMock->expects($this->once())
229+
->method('getParam')
230+
->with($this->equalTo('___store'))
231+
->will($this->returnValue('default'));
232+
233+
$this->storeManager->method('getStore')
234+
->with('default')
235+
->willReturn($this->currentStoreMock);
236+
210237
$this->httpContextMock->expects($this->at(0))
211238
->method('setValue')
212239
->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
@@ -220,4 +247,78 @@ public function testDispatchCurrentStoreCurrency()
220247
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
221248
);
222249
}
250+
251+
public function testDispatchStoreParameterIsArray()
252+
{
253+
$this->storeMock->expects($this->once())
254+
->method('getDefaultCurrencyCode')
255+
->will($this->returnValue(self::CURRENCY_DEFAULT));
256+
257+
$this->storeMock->expects($this->once())
258+
->method('getCode')
259+
->willReturn('default');
260+
$this->currentStoreMock->expects($this->once())
261+
->method('getCode')
262+
->willReturn('custom_store');
263+
264+
$store = [
265+
'_data' => [
266+
'code' => 500,
267+
]
268+
];
269+
270+
$this->httpRequestMock->expects($this->once())
271+
->method('getParam')
272+
->with($this->equalTo('___store'))
273+
->will($this->returnValue($store));
274+
275+
$this->storeManager->expects($this->once())
276+
->method('getStore')
277+
->with('500')
278+
->willReturn($this->currentStoreMock);
279+
280+
$this->httpContextMock->expects($this->at(0))
281+
->method('setValue')
282+
->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default');
283+
/** Make sure that current currency is taken from current store if no value is provided in session */
284+
$this->httpContextMock->expects($this->at(1))
285+
->method('setValue')
286+
->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT);
287+
288+
$result = $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock);
289+
$this->assertEquals(
290+
'ExpectedValue',
291+
$result
292+
);
293+
}
294+
295+
/**
296+
* @expectedException \InvalidArgumentException
297+
* @expectedExceptionMessage Invalid store parameter.
298+
*/
299+
public function testDispatchStoreParameterIsInvalidArray()
300+
{
301+
$this->storeMock->expects($this->never())
302+
->method('getDefaultCurrencyCode')
303+
->will($this->returnValue(self::CURRENCY_DEFAULT));
304+
305+
$this->storeMock->expects($this->never())
306+
->method('getCode')
307+
->willReturn('default');
308+
$this->currentStoreMock->expects($this->never())
309+
->method('getCode')
310+
->willReturn('custom_store');
311+
312+
$store = [
313+
'some' => [
314+
'code' => 500,
315+
]
316+
];
317+
318+
$this->httpRequestMock->expects($this->once())
319+
->method('getParam')
320+
->with($this->equalTo('___store'))
321+
->will($this->returnValue($store));
322+
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock);
323+
}
223324
}

0 commit comments

Comments
 (0)