Skip to content

Commit

Permalink
Always resolve the valid store code from baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed May 7, 2024
1 parent db611c8 commit 356c51b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Config
private const CONFIG_PATH_STORE_PATH_URL = 'web/url/store_path_url';
private const CONFIG_PATH_CUSTOM_PATH_MAPPER = 'web/url/custom_path_mapper';
private const CONFIG_PATH_UNSET_SINGLE_STORE_PATH = 'web/url/unset_single_store_path';
private const CONFIG_PATH_BASE_URL_RESOLVER = 'web/url/base_url_resolver';

private ?array $customPathMapper = null;

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

public function isBaseUrlResolverEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_BASE_URL_RESOLVER);
}

public function getStorePathType(): PathType
{
return PathType::from($this->scopeConfig->getValue(self::CONFIG_PATH_STORE_PATH_URL));
Expand Down
4 changes: 2 additions & 2 deletions Plugin/App/Request/StorePathInfoValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(

public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
{
if ($this->config->isEnabled()) {
if ($this->config->isBaseUrlResolverEnabled()) {
$uri = strtok($request->getUriString(), '?') . '/';
if ($uri !== false) {
if ($pathInfo === '') {
Expand All @@ -50,7 +50,7 @@ private function resolveByLinkUrl(string $uri): string
/** @var Store $store */
foreach ($this->storeRepository->getList() as $store) {
if ($store->getId() && str_starts_with($uri, $store->getBaseUrl())) {
$pathInfo = $store->getCode();
return $store->getCode();
}
}

Expand Down
6 changes: 6 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
</depends>
<comment>When enabled, websites with a single store won't use the Store Path in URLs.</comment>
</field>
<field id="base_url_resolver" type="select" translate="label comment" showInDefault="1" showInWebsite="0" showInStore="0" sortOrder="15" canRestore="1">
<label>Use Base Url Resolver</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>web/url/base_url_resolver</config_path>
<comment>When enabled, scope is resolved from the base url match.</comment>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<url>
<store_path_url>store_code</store_path_url>
<unset_single_store_path>1</unset_single_store_path>
<base_url_resolver>1</base_url_resolver>
</url>
</web>
</default>
Expand Down

0 comments on commit 356c51b

Please sign in to comment.