13
13
use Wizzy \Search \Services \Queue \SessionStorage \CategoriesSessionStorage ;
14
14
use Wizzy \Search \Services \Store \StoreAutocompleteConfig ;
15
15
use Magento \Framework \Event \ManagerInterface ;
16
+ use Wizzy \Search \Services \Store \StoreManager ;
16
17
17
18
class ConfigurableProductsData
18
19
{
@@ -22,7 +23,7 @@ class ConfigurableProductsData
22
23
private $ genderConfigurable ;
23
24
private $ colorConfigurable ;
24
25
private $ sizeConfigurable ;
25
-
26
+ private $ storeManager ;
26
27
private $ storeAutocompleteConfig ;
27
28
28
29
private $ categoriesManager ;
@@ -36,6 +37,10 @@ class ConfigurableProductsData
36
37
37
38
private $ eventManager ;
38
39
40
+ private $ storeId ;
41
+ private $ allStoreBaseUrls = null ;
42
+ private $ currentStoreBaseUrl = [];
43
+
39
44
public function __construct (
40
45
ManagerInterface $ eventManager ,
41
46
BrandConfigurable $ brandConfigurable ,
@@ -46,7 +51,8 @@ public function __construct(
46
51
StoreAutocompleteConfig $ storeAutocompleteConfig ,
47
52
AttributesManager $ attributesManager ,
48
53
CategoriesSessionStorage $ categoriesSessionStorage ,
49
- ProductsAttributesManager $ productsAttributesManager
54
+ ProductsAttributesManager $ productsAttributesManager ,
55
+ StoreManager $ storeManager
50
56
) {
51
57
$ this ->eventManager = $ eventManager ;
52
58
$ this ->brandConfigurable = $ brandConfigurable ;
@@ -62,8 +68,14 @@ public function __construct(
62
68
$ this ->productsAttributesManager = $ productsAttributesManager ;
63
69
$ this ->hasToIgnoreCategories = $ this ->storeAutocompleteConfig ->hasToIgnoreCategories ();
64
70
$ this ->categoriesToIgnoreInAutoComplete = $ this ->storeAutocompleteConfig ->getIgnoredCategories ();
71
+ $ this ->storeManager = $ storeManager ;
65
72
}
66
73
74
+ public function setStore ($ storeId )
75
+ {
76
+ $ this ->storeId = $ storeId ;
77
+ }
78
+
67
79
public function getBrand ($ categories , $ attributes , $ storeId )
68
80
{
69
81
return $ this ->brandConfigurable ->getValue ($ categories , $ attributes , $ storeId );
@@ -233,7 +245,6 @@ public function getProductCategories($product)
233
245
);
234
246
return $ dataObject ->getDataByKey ('categories ' );
235
247
}
236
-
237
248
private function getCategoryArray ($ category )
238
249
{
239
250
$ pathIds = $ category ->getPathIds ();
@@ -266,6 +277,34 @@ private function getCategoryArray($category)
266
277
$ parentUrlKey = '' ;
267
278
}
268
279
280
+ if ($ this ->allStoreBaseUrls === null ) {
281
+ $ this ->allStoreBaseUrls = $ this ->storeManager ->getAllStoreBaseUrls ();
282
+ }
283
+
284
+ if (!isset ($ this ->currentStoreBaseUrl [$ this ->storeId ])) {
285
+ $ this ->currentStoreBaseUrl [$ this ->storeId ] = $ this ->storeManager ->getCurrentStoreBaseUrl ();
286
+ ;
287
+ }
288
+
289
+ $ currentStoreBaseUrl = null ;
290
+
291
+ if ($ this ->currentStoreBaseUrl [$ this ->storeId ] &&
292
+ isset ($ this ->currentStoreBaseUrl [$ this ->storeId ]['base_url ' ])
293
+ ) {
294
+ $ currentStoreBaseUrl = $ this ->currentStoreBaseUrl [$ this ->storeId ];
295
+ $ currentStoreBaseUrl = $ currentStoreBaseUrl ['base_url ' ];
296
+ }
297
+
298
+ $ categoryUrl = $ category ->getUrl ();
299
+ foreach ($ this ->allStoreBaseUrls as $ store ) {
300
+ if (strpos ($ categoryUrl , $ store ['base_url ' ]) === 0 &&
301
+ isset ($ currentStoreBaseUrl ) && $ currentStoreBaseUrl !== null ) {
302
+ $ categoryUrl = str_replace ($ store ['base_url ' ], '' , $ categoryUrl );
303
+ $ categoryUrl = $ currentStoreBaseUrl ."" .$ categoryUrl ;
304
+ break ;
305
+ }
306
+ }
307
+
269
308
$ data =
270
309
['id ' => $ category ->getId (),
271
310
'value ' => $ category ->getName (),
@@ -276,7 +315,7 @@ private function getCategoryArray($category)
276
315
'level ' => (int ) $ category ->getLevel (),
277
316
'description ' => ($ category ->getDescription ()) ? $ category ->getDescription () : '' ,
278
317
'image ' => ($ category ->getImageUrl ()) ? $ category ->getImageUrl () : '' ,
279
- 'url ' => $ category -> getUrl () ,
318
+ 'url ' => $ categoryUrl ,
280
319
'isActive ' => $ category ->getIsActive (),
281
320
'pathIds ' => $ pathIds ,
282
321
'parentId ' => $ parentId ,
@@ -293,7 +332,7 @@ private function getCategoryArray($category)
293
332
294
333
$ data ['includeInMenu ' ] = $ includeInMenu ;
295
334
$ data ['isSearchable ' ] = $ isSearchable ;
296
-
335
+
297
336
return $ data ;
298
337
}
299
338
}
0 commit comments