9
9
10
10
class Configuration extends Algolia implements CollectionDataSourceInterface
11
11
{
12
+ //Placeholder for future implementation (requires customer renderer for hierarchicalMenu widget)
13
+ private const IS_CATEGORY_NAVIGATION_ENABLED = false ;
14
+
12
15
public function isSearchPage ()
13
16
{
14
17
if ($ this ->getConfigHelper ()->isInstantEnabled ()) {
@@ -30,6 +33,40 @@ public function isSearchPage()
30
33
return false ;
31
34
}
32
35
36
+ /**
37
+ * @param \Magento\Catalog\Model\Category $cat
38
+ * @return string
39
+ */
40
+ protected function initCategoryParentPath (\Magento \Catalog \Model \Category $ cat ): string {
41
+ $ path = '' ;
42
+ foreach ($ cat ->getPathIds () as $ treeCategoryId ) {
43
+ if ($ path ) {
44
+ $ path .= $ this ->getConfigHelper ()->getCategorySeparator ($ this ->getStoreId ());
45
+ }
46
+ $ path .= $ this ->getCategoryHelper ()->getCategoryName ($ treeCategoryId , $ this ->getStoreId ());
47
+ }
48
+ return $ path ;
49
+ }
50
+
51
+ /**
52
+ * @param \Magento\Catalog\Model\Category $cat
53
+ * @param string $parent
54
+ * @param array $arr
55
+ * @return array
56
+ */
57
+ protected function getChildCategoryUrls (\Magento \Catalog \Model \Category $ cat , string $ parent = '' , array $ arr = array ()): array {
58
+ if (!$ parent ) {
59
+ $ parent = $ this ->initCategoryParentPath ($ cat );
60
+ }
61
+
62
+ foreach ($ cat ->getChildrenCategories () as $ child ) {
63
+ $ key = $ parent ? $ parent . $ this ->getConfigHelper ()->getCategorySeparator ($ this ->getStoreId ()) . $ child ->getName () : $ child ->getName ();
64
+ $ arr [$ key ]['url ' ] = $ child ->getUrl ();
65
+ $ arr = array_merge ($ arr , $ this ->getChildCategoryUrls ($ child , $ key , $ arr ));
66
+ }
67
+ return $ arr ;
68
+ }
69
+
33
70
public function getConfiguration ()
34
71
{
35
72
$ config = $ this ->getConfigHelper ();
@@ -70,6 +107,7 @@ public function getConfiguration()
70
107
$ level = '' ;
71
108
$ categoryId = '' ;
72
109
$ parentCategoryName = '' ;
110
+ $ childCategories = [];
73
111
74
112
$ addToCartParams = $ this ->getAddToCartParams ();
75
113
@@ -88,14 +126,17 @@ public function getConfiguration()
88
126
89
127
if ($ category && $ category ->getDisplayMode () !== 'PAGE ' ) {
90
128
$ category ->getUrlInstance ()->setStore ($ this ->getStoreId ());
129
+ if (self ::IS_CATEGORY_NAVIGATION_ENABLED ) {
130
+ $ childCategories = $ this ->getChildCategoryUrls ($ category );
131
+ }
91
132
92
133
$ categoryId = $ category ->getId ();
93
134
94
135
$ level = -1 ;
95
136
foreach ($ category ->getPathIds () as $ treeCategoryId ) {
96
137
if ($ path !== '' ) {
97
- $ path .= ' /// ' ;
98
- }else {
138
+ $ path .= $ config -> getCategorySeparator () ;
139
+ } else {
99
140
$ parentCategoryName = $ categoryHelper ->getCategoryName ($ treeCategoryId , $ this ->getStoreId ());
100
141
}
101
142
@@ -144,7 +185,6 @@ public function getConfiguration()
144
185
}
145
186
146
187
$ attributesToFilter = $ config ->getAttributesToFilter ($ customerGroupId );
147
-
148
188
$ algoliaJsConfig = [
149
189
'instant ' => [
150
190
'enabled ' => $ config ->isInstantEnabled (),
@@ -154,6 +194,10 @@ public function getConfiguration()
154
194
'infiniteScrollEnabled ' => $ config ->isInfiniteScrollEnabled (),
155
195
'urlTrackedParameters ' => $ this ->getUrlTrackedParameters (),
156
196
'isSearchBoxEnabled ' => $ config ->isInstantSearchBoxEnabled (),
197
+ 'isVisualMerchEnabled ' => $ config ->isVisualMerchEnabled (),
198
+ 'categorySeparator ' => $ config ->getCategorySeparator (),
199
+ 'categoryPageIdAttribute ' => $ config ->getCategoryPageIdAttributeName (),
200
+ 'isCategoryNavigationEnabled ' => self ::IS_CATEGORY_NAVIGATION_ENABLED ,
157
201
'hidePagination ' => $ config ->hidePaginationInInstantSearchPage ()
158
202
],
159
203
'autocomplete ' => [
@@ -231,6 +275,7 @@ public function getConfiguration()
231
275
'path ' => $ path ,
232
276
'level ' => $ level ,
233
277
'parentCategory ' => $ parentCategoryName ,
278
+ 'childCategories ' => $ childCategories ,
234
279
'url ' => $ this ->getUrl ('*/*/* ' , ['_use_rewrite ' => true , '_forced_secure ' => true ])
235
280
],
236
281
'showCatsNotIncludedInNavigation ' => $ config ->showCatsNotIncludedInNavigation (),
0 commit comments