Skip to content

Commit bf2c005

Browse files
author
Alexander Akimov
authored
Merge pull request #2710 from magento-panda/MAGETWO-89905
[panda] MAGETWO-89905: Categories of the Main menu in the different Store View not updated when varnish enabled
2 parents 3660812 + 2895930 commit bf2c005

File tree

41 files changed

+877
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+877
-747
lines changed

app/code/Magento/CatalogUrlRewrite/Plugin/Store/Block/Switcher.php

Lines changed: 0 additions & 86 deletions
This file was deleted.

app/code/Magento/CatalogUrlRewrite/etc/frontend/di.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/code/Magento/Customer/Model/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public function authenticate($loginUrl = null)
487487
$this->response->setRedirect($loginUrl);
488488
} else {
489489
$arguments = $this->_customerUrl->getLoginUrlParams();
490-
if ($this->_session->getCookieShouldBeReceived() && $this->_createUrl()->getUseSession()) {
490+
if ($this->_createUrl()->getUseSession()) {
491491
$arguments += [
492492
'_query' => [
493493
$this->sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId(),

app/code/Magento/Customer/Test/Unit/Model/SessionTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,21 @@ public function testAuthenticate()
131131
$urlMock = $this->createMock(\Magento\Framework\Url::class);
132132
$urlMock->expects($this->exactly(2))
133133
->method('getUrl')
134-
->will($this->returnValue(''));
134+
->willReturn('');
135135
$urlMock->expects($this->once())
136136
->method('getRebuiltUrl')
137-
->will($this->returnValue(''));
138-
$this->urlFactoryMock->expects($this->exactly(3))
137+
->willReturn('');
138+
$this->urlFactoryMock->expects($this->exactly(4))
139139
->method('create')
140-
->will($this->returnValue($urlMock));
140+
->willReturn($urlMock);
141+
$urlMock->expects($this->once())
142+
->method('getUseSession')
143+
->willReturn(false);
141144

142145
$this->responseMock->expects($this->once())
143146
->method('setRedirect')
144147
->with('')
145-
->will($this->returnValue(''));
148+
->willReturn('');
146149

147150
$this->assertFalse($this->_model->authenticate());
148151
}

app/code/Magento/PageCache/Model/Config.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public function __construct(
113113
*
114114
* @return int
115115
* @api
116-
* @deprecated 100.2.0 see \Magento\PageCache\Model\VclGeneratorInterface::generateVcl
117116
*/
118117
public function getType()
119118
{
@@ -125,7 +124,6 @@ public function getType()
125124
*
126125
* @return int
127126
* @api
128-
* @deprecated 100.2.0 see \Magento\PageCache\Model\VclGeneratorInterface::generateVcl
129127
*/
130128
public function getTtl()
131129
{
@@ -255,7 +253,6 @@ protected function _getDesignExceptions()
255253
*
256254
* @return bool
257255
* @api
258-
* @deprecated 100.2.0 see \Magento\PageCache\Model\VclGeneratorInterface::generateVcl
259256
*/
260257
public function isEnabled()
261258
{

app/code/Magento/Store/App/Config/Type/Scopes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ private function convertIdPathToCodePath(array $patchChunks)
114114
public function clean()
115115
{
116116
$this->data = null;
117+
$this->idCodeMap = [];
117118
}
118119
}

app/code/Magento/Store/App/Response/Redirect.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ public function success($defaultUrl)
171171
*/
172172
public function updatePathParams(array $arguments)
173173
{
174-
if ($this->_session->getCookieShouldBeReceived()
175-
&& $this->_sidResolver->getUseSessionInUrl()
176-
&& $this->_canUseSessionIdInParam
177-
) {
178-
$arguments += [
179-
'_query' => [
180-
$this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId(),
181-
]
182-
];
183-
}
184174
return $arguments;
185175
}
186176

app/code/Magento/Store/Block/Switcher.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
namespace Magento\Store\Block;
1111

1212
use Magento\Directory\Helper\Data;
13+
use Magento\Framework\App\ActionInterface;
14+
use Magento\Framework\App\ObjectManager;
1315
use Magento\Store\Model\Group;
16+
use Magento\Framework\Url\Helper\Data as UrlHelper;
1417

1518
/**
1619
* @api
@@ -28,20 +31,28 @@ class Switcher extends \Magento\Framework\View\Element\Template
2831
*/
2932
protected $_postDataHelper;
3033

34+
/**
35+
* @var UrlHelper
36+
*/
37+
private $urlHelper;
38+
3139
/**
3240
* Constructs
3341
*
3442
* @param \Magento\Framework\View\Element\Template\Context $context
3543
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
3644
* @param array $data
45+
* @param UrlHelper $urlHelper
3746
*/
3847
public function __construct(
3948
\Magento\Framework\View\Element\Template\Context $context,
4049
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
41-
array $data = []
50+
array $data = [],
51+
UrlHelper $urlHelper = null
4252
) {
4353
$this->_postDataHelper = $postDataHelper;
4454
parent::__construct($context, $data);
55+
$this->urlHelper = $urlHelper ?: ObjectManager::getInstance()->get(UrlHelper::class);
4556
}
4657

4758
/**
@@ -220,15 +231,20 @@ public function getStoreName()
220231
* @param \Magento\Store\Model\Store $store
221232
* @param array $data
222233
* @return string
234+
* @throws \Magento\Framework\Exception\NoSuchEntityException
223235
*/
224236
public function getTargetStorePostData(\Magento\Store\Model\Store $store, $data = [])
225237
{
226-
$data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME]
227-
= $store->getCode();
228-
//We need to fromStore as true because it will enable proper URL
229-
//rewriting during store switching.
238+
$data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME] = $store->getCode();
239+
$data['___from_store'] = $this->_storeManager->getStore()->getCode();
240+
241+
$urlOnTargetStore = $store->getCurrentUrl(false);
242+
$data[ActionInterface::PARAM_NAME_URL_ENCODED] = $this->urlHelper->getEncodedUrl($urlOnTargetStore);
243+
244+
$url = $this->getUrl('stores/store/redirect');
245+
230246
return $this->_postDataHelper->getPostData(
231-
$store->getCurrentUrl(true),
247+
$url,
232248
$data
233249
);
234250
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
namespace Magento\Store\Controller\Store;
9+
10+
use Magento\Framework\App\Action\Context;
11+
use Magento\Framework\App\ResponseInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Store\Api\StoreRepositoryInterface;
14+
use Magento\Store\Api\StoreResolverInterface;
15+
use Magento\Store\Model\StoreResolver;
16+
use Magento\Framework\Session\SidResolverInterface;
17+
use Magento\Framework\Session\Generic as Session;
18+
19+
/**
20+
* Builds correct url to target store and performs redirect.
21+
*/
22+
class Redirect extends \Magento\Framework\App\Action\Action
23+
{
24+
/**
25+
* @var StoreRepositoryInterface
26+
*/
27+
private $storeRepository;
28+
29+
/**
30+
* @var StoreResolverInterface
31+
*/
32+
private $storeResolver;
33+
34+
/**
35+
* @var SidResolverInterface
36+
*/
37+
private $sidResolver;
38+
39+
/**
40+
* @var Session
41+
*/
42+
private $session;
43+
44+
/**
45+
* @param Context $context
46+
* @param StoreRepositoryInterface $storeRepository
47+
* @param StoreResolverInterface $storeResolver
48+
* @param Session $session
49+
* @param SidResolverInterface $sidResolver
50+
*/
51+
public function __construct(
52+
Context $context,
53+
StoreRepositoryInterface $storeRepository,
54+
StoreResolverInterface $storeResolver,
55+
Session $session,
56+
SidResolverInterface $sidResolver
57+
) {
58+
parent::__construct($context);
59+
$this->storeRepository = $storeRepository;
60+
$this->storeResolver = $storeResolver;
61+
$this->session = $session;
62+
$this->sidResolver = $sidResolver;
63+
}
64+
65+
/**
66+
* @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
67+
* @throws NoSuchEntityException
68+
*/
69+
public function execute()
70+
{
71+
/** @var \Magento\Store\Model\Store $currentStore */
72+
$currentStore = $this->storeRepository->getById($this->storeResolver->getCurrentStoreId());
73+
$targetStoreCode = $this->_request->getParam(StoreResolver::PARAM_NAME);
74+
$fromStoreCode = $this->_request->getParam('___from_store');
75+
$error = null;
76+
77+
if ($targetStoreCode === null) {
78+
return $this->_redirect($currentStore->getBaseUrl());
79+
}
80+
81+
try {
82+
/** @var \Magento\Store\Model\Store $targetStore */
83+
$fromStore = $this->storeRepository->get($fromStoreCode);
84+
} catch (NoSuchEntityException $e) {
85+
$error = __('Requested store is not found');
86+
}
87+
88+
if ($error !== null) {
89+
$this->messageManager->addErrorMessage($error);
90+
$this->_redirect->redirect($this->_response, $currentStore->getBaseUrl());
91+
} else {
92+
$encodedUrl = $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED);
93+
94+
$query = [
95+
'___from_store' => $fromStore->getCode(),
96+
StoreResolverInterface::PARAM_NAME => $targetStoreCode,
97+
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $encodedUrl,
98+
];
99+
100+
if ($this->sidResolver->getUseSessionInUrl()) {
101+
// allow customers to stay logged in during store switching
102+
$sidName = $this->sidResolver->getSessionIdQueryParam($this->session);
103+
$query[$sidName] = $this->session->getSessionId();
104+
}
105+
106+
$arguments = [
107+
'_nosid' => true,
108+
'_query' => $query
109+
];
110+
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)