Skip to content

Commit c12f039

Browse files
authored
ENGCOM-4050: Fixed store switcher doesn't work multistore setup with different product urls issue #19798
2 parents 2d1b20a + f4e6d90 commit c12f039

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

app/code/Magento/UrlRewrite/Model/StoreSwitcher/RewriteUrl.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function switch(StoreInterface $fromStore, StoreInterface $targetStore, s
6868
UrlRewrite::STORE_ID => $oldStoreId,
6969
]);
7070
if ($oldRewrite) {
71+
$targetUrl = $targetStore->getBaseUrl();
7172
// look for url rewrite match on the target store
7273
$currentRewrite = $this->urlFinder->findOneByData([
73-
UrlRewrite::REQUEST_PATH => $urlPath,
74+
UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
7475
UrlRewrite::STORE_ID => $targetStore->getId(),
7576
]);
76-
if (null === $currentRewrite) {
77-
/** @var \Magento\Framework\App\Response\Http $response */
78-
$targetUrl = $targetStore->getBaseUrl();
77+
if ($currentRewrite) {
78+
$targetUrl .= $currentRewrite->getRequestPath();
7979
}
8080
} else {
8181
$existingRewrite = $this->urlFinder->findOneByData([
@@ -86,7 +86,6 @@ public function switch(StoreInterface $fromStore, StoreInterface $targetStore, s
8686
$targetUrl = $targetStore->getBaseUrl();
8787
}
8888
}
89-
9089
return $targetUrl;
9190
}
9291
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function testSwitchToExistingPage(): void
9292
$storeRepository = $this->objectManager->create(\Magento\Store\Api\StoreRepositoryInterface::class);
9393
$toStore = $storeRepository->get($toStoreCode);
9494

95-
$redirectUrl = $expectedUrl = "http://localhost/page-c";
95+
$redirectUrl = "http://localhost/index.php/page-c/";
96+
$expectedUrl = "http://localhost/index.php/page-c-on-2nd-store";
9697

9798
$this->assertEquals($expectedUrl, $this->storeSwitcher->switch($fromStore, $toStore, $redirectUrl));
9899
}

0 commit comments

Comments
 (0)