Skip to content

Commit f4e6d90

Browse files
ENGCOM-4050: Fixed store switcher doesn't work multistore setup with different product urls issue #19798
- Merge Pull Request #19798 from janakbhimani/magento2:issue-19714 - Merged commits: 1. 927ca80 2. b36dc04 3. 3d882cf 4. c7b4aae 5. 54a4039 6. 618d8e3 7. 8a05dbb
2 parents da1173a + 8a05dbb commit f4e6d90

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
@@ -66,17 +66,16 @@ public function switch(StoreInterface $fromStore, StoreInterface $targetStore, s
6666
UrlRewrite::STORE_ID => $oldStoreId,
6767
]);
6868
if ($oldRewrite) {
69+
$targetUrl = $targetStore->getBaseUrl();
6970
// look for url rewrite match on the target store
7071
$currentRewrite = $this->urlFinder->findOneByData([
71-
UrlRewrite::REQUEST_PATH => $urlPath,
72+
UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
7273
UrlRewrite::STORE_ID => $targetStore->getId(),
7374
]);
74-
if (null === $currentRewrite) {
75-
/** @var \Magento\Framework\App\Response\Http $response */
76-
$targetUrl = $targetStore->getBaseUrl();
75+
if ($currentRewrite) {
76+
$targetUrl .= $currentRewrite->getRequestPath();
7777
}
7878
}
79-
8079
return $targetUrl;
8180
}
8281
}

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)