diff --git a/Model/Config.php b/Model/Config.php index 0707a04..5f22ac0 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -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; @@ -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)); diff --git a/Plugin/App/Request/StorePathInfoValidator.php b/Plugin/App/Request/StorePathInfoValidator.php index 5d721f6..9975780 100644 --- a/Plugin/App/Request/StorePathInfoValidator.php +++ b/Plugin/App/Request/StorePathInfoValidator.php @@ -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 === '') { @@ -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(); } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 6de6fbd..a591174 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -43,6 +43,12 @@ When enabled, websites with a single store won't use the Store Path in URLs. + + + Magento\Config\Model\Config\Source\Yesno + web/url/base_url_resolver + When enabled, scope is resolved from the base url match. + diff --git a/etc/config.xml b/etc/config.xml index 8c8425c..36d32e6 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -11,6 +11,7 @@ store_code 1 + 1