Skip to content

Commit 8992f22

Browse files
committed
Fix multi domain websites
1 parent fb4ca71 commit 8992f22

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Plugin/App/Request/PathInfo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
namespace Opengento\StorePathUrl\Plugin\App\Request;
88

99
use Magento\Framework\App\Request\PathInfo as PathInfoSubject;
10+
use Magento\Framework\App\RequestInterface;
1011
use Opengento\StorePathUrl\Model\Config;
1112
use Opengento\StorePathUrl\Service\StorePathFixer;
1213

1314
class PathInfo
1415
{
1516
public function __construct(
1617
private Config $config,
17-
private StorePathFixer $storePathFixer
18+
private StorePathFixer $storePathFixer,
19+
private RequestInterface $request
1820
) {}
1921

2022
public function beforeGetPathInfo(PathInfoSubject $subject, string $requestUri, string $baseUrl): array
2123
{
2224
if ($this->config->isEnabled()) {
23-
$requestUri = $this->storePathFixer->fix($baseUrl, $requestUri);
25+
$requestUri = $this->storePathFixer->fix($baseUrl ? $requestUri : $this->request->getUriString(), $requestUri);
2426
}
2527

2628
return [$requestUri, $baseUrl];

Service/StorePathFixer.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,24 @@
99
use Magento\Store\Api\StoreRepositoryInterface;
1010
use Magento\Store\Model\Store;
1111

12-
use function parse_url;
1312
use function str_starts_with;
1413

15-
use const PHP_URL_PATH;
16-
1714
class StorePathFixer
1815
{
1916
public function __construct(
2017
private StoreRepositoryInterface $storeRepository,
2118
private UriUtils $uriUtils
2219
) {}
2320

21+
/**
22+
* Replace the request uri path with the store code, if the base url match any of the registered store base url.
23+
*/
2424
public function fix(string $baseUrl, string $requestUri): string
2525
{
2626
/** @var Store $store */
2727
foreach ($this->storeRepository->getList() as $store) {
28-
if ($store->getId()) {
29-
if ($baseUrl === '') {
30-
$path = parse_url($store->getBaseUrl(), PHP_URL_PATH);
31-
if (str_starts_with($requestUri . '/', $path)) {
32-
return $this->uriUtils->replacePathCode($requestUri, $store);
33-
}
34-
} elseif (str_starts_with($baseUrl . $requestUri, $store->getBaseUrl())) {
35-
return $this->uriUtils->replacePathCode($requestUri, $store);
36-
}
28+
if ($store->getId() && str_starts_with($baseUrl, $store->getBaseUrl())) {
29+
return $this->uriUtils->replacePathCode($requestUri, $store);
3730
}
3831
}
3932

0 commit comments

Comments
 (0)