@@ -132,7 +132,7 @@ define([
132
132
buildAutocompleteOptions ( searchClient , sources , plugins ) {
133
133
const debounced = this . debounce ( items => Promise . resolve ( items ) , DEBOUNCE_MS ) ;
134
134
135
- const autocompleteConfig = [ ] ;
135
+ const autocompleteConfig = this . transformSources ( searchClient , sources ) ;
136
136
137
137
let options = algoliaCommon . triggerHooks ( 'beforeAutocompleteOptions' , { } ) ;
138
138
@@ -159,12 +159,11 @@ define([
159
159
shouldPanelOpen ( { state} ) {
160
160
return state . query . length >= MIN_SEARCH_LENGTH_CHARS ;
161
161
} ,
162
+ // Set debug to true, to be able to remove keyboard and be able to scroll in autocomplete menu
163
+ debug : algoliaCommon . isMobile ( ) ,
164
+ plugins
162
165
} ;
163
166
164
- if ( algoliaCommon . isMobile ( ) === true ) {
165
- // Set debug to true, to be able to remove keyboard and be able to scroll in autocomplete menu
166
- options . debug = true ;
167
- }
168
167
169
168
// DEPRECATED Do not use - Retained for backward compatibility but `algoliaHookBeforeAutocompleteStart` will be removed in a future version
170
169
if ( typeof algoliaHookBeforeAutocompleteStart === 'function' ) {
@@ -184,6 +183,20 @@ define([
184
183
options = hookResult . shift ( ) ;
185
184
}
186
185
186
+ options = algoliaCommon . triggerHooks ( 'afterAutocompleteOptions' , options ) ;
187
+
188
+ return options ;
189
+ } ,
190
+
191
+ /**
192
+ * Validate and merge behaviors for custom sources
193
+ *
194
+ * @param searchClient
195
+ * @param sources Magento sources
196
+ * @returns Algolia sources
197
+ */
198
+ transformSources ( searchClient , sources ) {
199
+ const autocompleteConfig = [ ] ;
187
200
sources . forEach ( ( data ) => {
188
201
if ( ! data . sourceId ) {
189
202
console . error (
@@ -225,12 +238,7 @@ define([
225
238
...( data . getItemUrl && { getItemUrl : data . getItemUrl } ) ,
226
239
} ) ;
227
240
} ) ;
228
-
229
- options . plugins = plugins ;
230
-
231
- options = algoliaCommon . triggerHooks ( 'afterAutocompleteOptions' , options ) ;
232
-
233
- return options ;
241
+ return autocompleteConfig ;
234
242
} ,
235
243
236
244
/**
0 commit comments