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,30 @@ 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
+ if ($ this ->currentStoreBaseUrl [$ this ->storeId ] && isset ($ this ->currentStoreBaseUrl [$ this ->storeId ]['base_url ' ])){
290
+ $ currentStoreBaseUrl = $ this ->currentStoreBaseUrl [$ this ->storeId ];
291
+ $ currentStoreBaseUrl = $ currentStoreBaseUrl ['base_url ' ];
292
+ }
293
+
294
+ $ categoryUrl = $ category ->getUrl ();
295
+ foreach ($ this ->allStoreBaseUrls as $ store ) {
296
+ if (strpos ($ categoryUrl , $ store ['base_url ' ]) === 0 ) {
297
+ $ categoryUrl = str_replace ($ store ['base_url ' ], '' , $ categoryUrl );
298
+ break ;
299
+ }
300
+ }
301
+
302
+ $ categoryUrl = $ currentStoreBaseUrl ."" .$ categoryUrl ;
303
+
269
304
$ data =
270
305
['id ' => $ category ->getId (),
271
306
'value ' => $ category ->getName (),
@@ -276,7 +311,7 @@ private function getCategoryArray($category)
276
311
'level ' => (int ) $ category ->getLevel (),
277
312
'description ' => ($ category ->getDescription ()) ? $ category ->getDescription () : '' ,
278
313
'image ' => ($ category ->getImageUrl ()) ? $ category ->getImageUrl () : '' ,
279
- 'url ' => $ category -> getUrl () ,
314
+ 'url ' => $ categoryUrl ,
280
315
'isActive ' => $ category ->getIsActive (),
281
316
'pathIds ' => $ pathIds ,
282
317
'parentId ' => $ parentId ,
@@ -293,7 +328,7 @@ private function getCategoryArray($category)
293
328
294
329
$ data ['includeInMenu ' ] = $ includeInMenu ;
295
330
$ data ['isSearchable ' ] = $ isSearchable ;
296
-
331
+
297
332
return $ data ;
298
333
}
299
334
}
0 commit comments