@@ -99,23 +99,29 @@ private function resolveByWebUrl(string $uri): string
9999 if ($ store ->getId () && str_starts_with ($ uri , $ store ->getBaseUrl (UrlInterface::URL_TYPE_WEB ))) {
100100 try {
101101 $ website = $ store ->getWebsite ();
102- if ($ website ->getDefaultGroup ()->getDefaultStore ()->getCode () === $ store ->getCode ()){
103- return $ store ->getCode ();
104- }
105102 if ($ website ->getIsDefault ()) {
106- if ($ store ->isDefault ()) {
103+ if ((int )$ website ->getDefaultGroup ()->getDefaultStoreId () === (int )$ store ->getId ()) {
104+ // If it's the default store from the default group of the default website
107105 return $ store ->getCode ();
108106 }
109- $ matches [0 ] = $ store ->getCode ();
110- } elseif ($ store ->isDefault ()) {
111- $ matches [1 ] = $ store ->getCode ();
112- } else {
107+ if (!isset ($ matches [0 ]) && $ store ->isDefault ()) {
108+ // If it's the default store from any group of the default website
109+ $ matches [0 ] = $ store ->getCode ();
110+ } elseif (!isset ($ matches [1 ])) {
111+ // If it's any store from the default website
112+ $ matches [1 ] = $ store ->getCode ();
113+ }
114+ } elseif (!isset ($ matches [2 ]) && $ store ->isDefault ()) {
115+ // If nothing match, any default store has the priority
113116 $ matches [2 ] = $ store ->getCode ();
117+ } elseif (!isset ($ matches [3 ])) {
118+ // If nothing match, we use the first store we found
119+ $ matches [3 ] = $ store ->getCode ();
114120 }
115121 } catch (NoSuchEntityException ) {}
116122 }
117123 }
118124
119- return $ matches [0 ] ?? $ matches [1 ] ?? $ matches [2 ] ?? '' ;
125+ return $ matches [0 ] ?? $ matches [1 ] ?? $ matches [2 ] ?? $ matches [ 3 ] ?? '' ;
120126 }
121127}
0 commit comments