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