Skip to content

Commit 97b6917

Browse files
committed
Optim + fix store resolver when path is unset
1 parent d83c33d commit 97b6917

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

App/Request/PathInfoProcessor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Store\Api\StoreRepositoryInterface;
1313
use Magento\Store\App\Request\PathInfoProcessor as AppPathInfoProcessor;
1414
use Magento\Store\App\Request\StorePathInfoValidator;
15+
use Opengento\StorePathUrl\Model\Config;
1516
use Opengento\StorePathUrl\Service\PathResolver;
1617

1718
use function str_starts_with;
@@ -23,11 +24,17 @@ class PathInfoProcessor extends AppPathInfoProcessor
2324
public function __construct(
2425
private StorePathInfoValidator $storePathInfoValidator,
2526
private PathResolver $pathResolver,
26-
private StoreRepositoryInterface $storeRepository
27+
private StoreRepositoryInterface $storeRepository,
28+
private Config $config,
29+
private AppPathInfoProcessor $subject
2730
) {}
2831

2932
public function process(RequestInterface $request, $pathInfo): string
3033
{
34+
if (!$this->config->isEnabled()) {
35+
return $this->subject->process($request, $pathInfo);
36+
}
37+
3138
$storeCode = $this->storePathInfoValidator->getValidStoreCode($request, $pathInfo);
3239
if ($storeCode !== null) {
3340
try {

Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
public function isEnabled(): bool
3131
{
3232
return $this->scopeConfig->isSetFlag(Store::XML_PATH_STORE_IN_URL)
33-
&& $this->getStorePathType() !== PathType::StoreCode;
33+
&& ($this->getStorePathType() !== PathType::StoreCode || $this->isUnsetSingleStorePath());
3434
}
3535

3636
public function getStorePathType(): PathType

Plugin/App/Request/StorePathInfoValidator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use function explode;
1818
use function parse_url;
1919
use function strtok;
20-
use function trim;
2120

2221
use const PHP_URL_PATH;
2322

@@ -33,7 +32,7 @@ public function beforeGetValidStoreCode(Subject $subject, Http $request, string
3332
if ($this->config->isEnabled()) {
3433
$uri = explode('?', $request->getUriString())[0] . '/';
3534
if ($pathInfo === '') {
36-
$pathInfo = strtok(trim(parse_url($uri, PHP_URL_PATH), '/'), '/');
35+
$pathInfo = strtok(parse_url($uri, PHP_URL_PATH), '/');
3736
}
3837
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri, $pathInfo);
3938
}

0 commit comments

Comments
 (0)