File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change 7
7
namespace Opengento \StorePathUrl \Plugin \App \Request ;
8
8
9
9
use Magento \Framework \App \Request \PathInfo as PathInfoSubject ;
10
+ use Magento \Framework \App \RequestInterface ;
10
11
use Opengento \StorePathUrl \Model \Config ;
11
12
use Opengento \StorePathUrl \Service \StorePathFixer ;
12
13
13
14
class PathInfo
14
15
{
15
16
public function __construct (
16
17
private Config $ config ,
17
- private StorePathFixer $ storePathFixer
18
+ private StorePathFixer $ storePathFixer ,
19
+ private RequestInterface $ request
18
20
) {}
19
21
20
22
public function beforeGetPathInfo (PathInfoSubject $ subject , string $ requestUri , string $ baseUrl ): array
21
23
{
22
24
if ($ this ->config ->isEnabled ()) {
23
- $ requestUri = $ this ->storePathFixer ->fix ($ baseUrl , $ requestUri );
25
+ $ requestUri = $ this ->storePathFixer ->fix ($ baseUrl ? $ requestUri : $ this -> request -> getUriString () , $ requestUri );
24
26
}
25
27
26
28
return [$ requestUri , $ baseUrl ];
Original file line number Diff line number Diff line change 9
9
use Magento \Store \Api \StoreRepositoryInterface ;
10
10
use Magento \Store \Model \Store ;
11
11
12
- use function parse_url ;
13
12
use function str_starts_with ;
14
13
15
- use const PHP_URL_PATH ;
16
-
17
14
class StorePathFixer
18
15
{
19
16
public function __construct (
20
17
private StoreRepositoryInterface $ storeRepository ,
21
18
private UriUtils $ uriUtils
22
19
) {}
23
20
21
+ /**
22
+ * Replace the request uri path with the store code, if the base url match any of the registered store base url.
23
+ */
24
24
public function fix (string $ baseUrl , string $ requestUri ): string
25
25
{
26
26
/** @var Store $store */
27
27
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 );
37
30
}
38
31
}
39
32
You can’t perform that action at this time.
0 commit comments