Skip to content

Commit d8ad900

Browse files
committed
MAGETWO-89905: Categories of the Main menu in the different Store View not updated when varnish enabled
- Add session sharing between stores; - Modify integration test;
1 parent bfcf612 commit d8ad900

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

app/code/Magento/Store/Controller/Store/Redirect.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,22 @@ public function execute()
9090
$this->_redirect->redirect($this->_response, $currentStore->getBaseUrl());
9191
} else {
9292
$encodedUrl = $this->_request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED);
93-
$sidName = $this->sidResolver->getSessionIdQueryParam($this->session);
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+
}
94105

95106
$arguments = [
96107
'_nosid' => true,
97-
'_query' =>
98-
[
99-
'___from_store' => $fromStore->getCode(),
100-
StoreResolverInterface::PARAM_NAME => $targetStoreCode,
101-
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $encodedUrl,
102-
$sidName => $this->session->getSessionId()
103-
]
108+
'_query' => $query
104109
];
105110
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);
106111
}

dev/tests/integration/testsuite/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrlTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\UrlRewrite\Model\StoreSwitcher;
77

8+
use Magento\Catalog\Api\ProductRepositoryInterface;
89
use Magento\Framework\App\Config\ReinitableConfigInterface;
910
use Magento\Framework\App\Config\Value;
1011
use Magento\Store\Api\Data\StoreInterface;
@@ -25,6 +26,11 @@ class RewriteUrlTest extends \PHPUnit\Framework\TestCase
2526
*/
2627
private $objectManager;
2728

29+
/**
30+
* @var ProductRepositoryInterface
31+
*/
32+
private $productRepository;
33+
2834
/**
2935
* Class dependencies initialization
3036
*
@@ -34,10 +40,12 @@ protected function setUp()
3440
{
3541
$this->objectManager = Bootstrap::getObjectManager();
3642
$this->storeSwitcher = $this->objectManager->get(StoreSwitcher::class);
43+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
3744
}
3845

3946
/**
4047
* @magentoDataFixture Magento/UrlRewrite/_files/url_rewrite.php
48+
* @magentoDataFixture Magento/Catalog/_files/category_product.php
4149
* @return void
4250
* @throws StoreSwitcher\CannotSwitchStoreException
4351
* @throws \Magento\Framework\Exception\NoSuchEntityException
@@ -56,7 +64,9 @@ public function testSwitchToNonExistingPage()
5664

5765
$this->setBaseUrl($toStore);
5866

59-
$redirectUrl = "http://domain.com/some-random-url/absent-in-url-rewrite.html";
67+
$product = $this->productRepository->get('simple333');
68+
69+
$redirectUrl = "http://domain.com/{$product->getUrlKey()}.html";
6070
$expectedUrl = $toStore->getBaseUrl();
6171

6272
$this->assertEquals($expectedUrl, $this->storeSwitcher->switch($fromStore, $toStore, $redirectUrl));

0 commit comments

Comments
 (0)