Skip to content

Commit 196ab80

Browse files
authored
Fix store code resolver when store in path is disabled
1 parent f8d1968 commit 196ab80

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: Plugin/App/Request/StorePathInfoValidator.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Opengento\StorePathUrl\Plugin\App\Request;
99

1010
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\UrlInterface;
1314
use Magento\Store\Api\StoreRepositoryInterface;
@@ -31,14 +32,29 @@ public function __construct(
3132

3233
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
3334
{
34-
if (++$this->stack === 1 && $this->config->isBaseUrlResolverEnabled()) {
35+
if (++$this->stack === 1 && $this->config->isStoreInPath() && $this->config->isBaseUrlResolverEnabled()) {
3536
$storeCode = $this->resolveStoreCode($request, $pathInfo);
3637
$pathInfo = $storeCode === '' ? $pathInfo : $storeCode;
3738
}
3839
$this->stack--;
3940

4041
return [$request, $pathInfo];
4142
}
43+
44+
public function afterGetValidStoreCode(Subject $subject, ?string $store, Http $request, string $path = ''): ?string
45+
{
46+
if (!$this->config->isStoreInPath() && $this->config->isBaseUrlResolverEnabled()) {
47+
try {
48+
$store = $this->storeRepository->getActiveStoreByCode(
49+
$this->resolveStoreCode($request, $path)
50+
)->getCode();
51+
} catch (LocalizedException) {
52+
$store = null;
53+
}
54+
}
55+
56+
return $store;
57+
}
4258

4359
private function resolveStoreCode(Http $request, string $pathInfo): string
4460
{

0 commit comments

Comments
 (0)