Skip to content

Commit b760ad9

Browse files
authored
Fix store code resolver for store configured with empty path
1 parent 2227540 commit b760ad9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Plugin/App/Request/StorePathInfoValidator.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,34 @@ private function resolveStoreCode(Http $request, string $pathInfo): string
4444
{
4545
$uri = strtok($request->getUriString(), '?') . '/';
4646
if ($uri !== false) {
47-
if ($pathInfo === '') {
48-
$pathInfo = parse_url($uri, PHP_URL_PATH);
49-
if ($pathInfo === false) {
50-
return '';
51-
}
52-
$pathInfo = strtok($pathInfo, '/');
47+
$pathInfo = $pathInfo ?: parse_url($uri, PHP_URL_PATH);
48+
if ($pathInfo === false) {
49+
return '';
5350
}
54-
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri);
51+
$pathInfo = $this->resolveByLinkUrl($uri) ?: $this->resolveByWebUrl($uri);
5552
}
5653

5754
return $pathInfo;
5855
}
5956

6057
private function resolveByLinkUrl(string $uri): string
6158
{
59+
$storeCode = '';
6260
/** @var Store $store */
6361
foreach ($this->storeRepository->getList() as $store) {
64-
if ($store->getId() && str_starts_with($uri, $store->getBaseUrl())) {
65-
return $store->getCode();
62+
if ($store->getId()) {
63+
$storeBaseUrl = $store->getBaseUrl();
64+
if (str_starts_with($uri, $storeBaseUrl)) {
65+
$path = trim((string)parse_url($storeBaseUrl, PHP_URL_PATH), '/');
66+
$storeCode = $store->getCode();
67+
if ($path !== '') {
68+
return $storeCode;
69+
}
70+
}
6671
}
6772
}
6873

69-
return '';
74+
return $storeCode;
7075
}
7176

7277
private function resolveByWebUrl(string $uri): string

0 commit comments

Comments
 (0)