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 77namespace Opengento \StorePathUrl \Plugin \App \Request ;
88
99use Magento \Framework \App \Request \PathInfo as PathInfoSubject ;
10+ use Magento \Framework \App \RequestInterface ;
1011use Opengento \StorePathUrl \Model \Config ;
1112use Opengento \StorePathUrl \Service \StorePathFixer ;
1213
1314class 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 ];
Original file line number Diff line number Diff line change 99use Magento \Store \Api \StoreRepositoryInterface ;
1010use Magento \Store \Model \Store ;
1111
12- use function parse_url ;
1312use function str_starts_with ;
1413
15- use const PHP_URL_PATH ;
16-
1714class 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
You can’t perform that action at this time.
0 commit comments