Skip to content

Commit 356c51b

Browse files
committed
Always resolve the valid store code from baseUrl
1 parent db611c8 commit 356c51b

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Model/Config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Config
2020
private const CONFIG_PATH_STORE_PATH_URL = 'web/url/store_path_url';
2121
private const CONFIG_PATH_CUSTOM_PATH_MAPPER = 'web/url/custom_path_mapper';
2222
private const CONFIG_PATH_UNSET_SINGLE_STORE_PATH = 'web/url/unset_single_store_path';
23+
private const CONFIG_PATH_BASE_URL_RESOLVER = 'web/url/base_url_resolver';
2324

2425
private ?array $customPathMapper = null;
2526

@@ -34,6 +35,11 @@ public function isEnabled(): bool
3435
&& ($this->getStorePathType() !== PathType::StoreCode || $this->isUnsetSingleStorePath());
3536
}
3637

38+
public function isBaseUrlResolverEnabled(): bool
39+
{
40+
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_BASE_URL_RESOLVER);
41+
}
42+
3743
public function getStorePathType(): PathType
3844
{
3945
return PathType::from($this->scopeConfig->getValue(self::CONFIG_PATH_STORE_PATH_URL));

Plugin/App/Request/StorePathInfoValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929

3030
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
3131
{
32-
if ($this->config->isEnabled()) {
32+
if ($this->config->isBaseUrlResolverEnabled()) {
3333
$uri = strtok($request->getUriString(), '?') . '/';
3434
if ($uri !== false) {
3535
if ($pathInfo === '') {
@@ -50,7 +50,7 @@ private function resolveByLinkUrl(string $uri): string
5050
/** @var Store $store */
5151
foreach ($this->storeRepository->getList() as $store) {
5252
if ($store->getId() && str_starts_with($uri, $store->getBaseUrl())) {
53-
$pathInfo = $store->getCode();
53+
return $store->getCode();
5454
}
5555
}
5656

etc/adminhtml/system.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
</depends>
4444
<comment>When enabled, websites with a single store won't use the Store Path in URLs.</comment>
4545
</field>
46+
<field id="base_url_resolver" type="select" translate="label comment" showInDefault="1" showInWebsite="0" showInStore="0" sortOrder="15" canRestore="1">
47+
<label>Use Base Url Resolver</label>
48+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
49+
<config_path>web/url/base_url_resolver</config_path>
50+
<comment>When enabled, scope is resolved from the base url match.</comment>
51+
</field>
4652
</group>
4753
</section>
4854
</system>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<url>
1212
<store_path_url>store_code</store_path_url>
1313
<unset_single_store_path>1</unset_single_store_path>
14+
<base_url_resolver>1</base_url_resolver>
1415
</url>
1516
</web>
1617
</default>

0 commit comments

Comments
 (0)