Skip to content

Commit 68a2605

Browse files
committed
MAGETWO-89905: Categories of the Main menu in the different Store View not updated when varnish enabled
- Moved plugin to UrlRewrite module;
1 parent 62c9e02 commit 68a2605

File tree

4 files changed

+8
-37
lines changed

4 files changed

+8
-37
lines changed

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

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

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public function __construct(
105105
*/
106106
public function execute()
107107
{
108-
$currentActiveStore = $this->storeManager->getStore();
109108
$storeCode = $this->_request->getParam(
110109
StoreResolver::PARAM_NAME,
111110
$this->storeCookieManager->getStoreCodeFromCookie()
@@ -141,18 +140,6 @@ public function execute()
141140
$this->storeCookieManager->setStoreCookie($store);
142141
}
143142

144-
if ($store->isUseStoreInUrl()) {
145-
// Change store code in redirect url
146-
if (strpos($redirectUrl, $currentActiveStore->getBaseUrl()) !== false) {
147-
$redirectUrl = str_replace(
148-
$currentActiveStore->getBaseUrl(),
149-
$store->getBaseUrl(),
150-
$redirectUrl
151-
);
152-
} else {
153-
$redirectUrl = $store->getBaseUrl();
154-
}
155-
}
156143
$this->getResponse()->setRedirect($redirectUrl);
157144
}
158145
}

app/code/Magento/CatalogUrlRewrite/Plugin/Store/Controller/Store/SwitchAction.php renamed to app/code/Magento/UrlRewrite/Plugin/Store/Controller/Store/SwitchAction.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\CatalogUrlRewrite\Plugin\Store\Controller\Store;
7+
namespace Magento\UrlRewrite\Plugin\Store\Controller\Store;
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Exception\LocalizedException;
@@ -19,8 +19,7 @@
1919
use Magento\Framework\App\ResponseInterface;
2020

2121
/**
22-
* Plugin makes connection between Store and UrlRewrite modules
23-
* because Magento\Store\Controller\Store\SwitchAction should not know about UrlRewrite module functionality
22+
* Plugin handles url rewrites for redirect url
2423
*
2524
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2625
*/
@@ -101,22 +100,16 @@ public function afterExecute(\Magento\Store\Controller\Store\SwitchAction $subje
101100

102101
if ($store->isUseStoreInUrl()) {
103102
// Remove store code in redirect url for correct rewrite search
104-
$urlPath = str_replace(
105-
$store->getCode() . '/',
106-
'',
107-
$urlPath
108-
);
103+
$storeCode = $store->getCode() . '/';
104+
$pattern = "@^($storeCode)@";
105+
$urlPath = preg_replace($pattern, '', $urlPath);
109106
}
110107

111108
try {
112109
$oldStoreId = $this->storeRepository->get($fromStore)->getId();
113110
$oldRewrite = $this->urlFinder->findOneByData([
114111
UrlRewrite::REQUEST_PATH => $urlPath,
115112
UrlRewrite::STORE_ID => $oldStoreId,
116-
UrlRewrite::ENTITY_TYPE => [
117-
\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
118-
\Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator::ENTITY_TYPE,
119-
]
120113
]);
121114
} catch (NoSuchEntityException $exception) {
122115
$oldRewrite = null;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
</argument>
1818
</arguments>
1919
</type>
20+
<type name="Magento\Store\Controller\Store\SwitchAction">
21+
<plugin name="store_switcher_plugin" type="Magento\UrlRewrite\Plugin\Store\Controller\Store\SwitchAction"/>
22+
</type>
2023
</config>

0 commit comments

Comments
 (0)