Created
February 7, 2018 12:56
-
-
Save JanPetr/c37f4b9731b268706b9068c0d361e2cc to your computer and use it in GitHub Desktop.
Code to replace Magento extension's query suggestions by Algolia powered query suggestions Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function algoliaHookBeforeAutocompleteStart(sources, options, algoliaClient) { | |
for (var i = 0; i < sources.length; i++) { | |
if (sources[i].name === 'suggestions') { | |
var index = algoliaClient.initIndex('products_suggestions_query_suggestions'), | |
suggestionsSource = algoliaBundle.$.fn.autocomplete.sources.hits(index, { | |
hitsPerPage: 2 // FIX IT | |
}); | |
sources[i] = { | |
source: suggestionsSource, | |
displayKey: 'query', | |
name: 'suggestions', | |
templates: { | |
suggestion: function (hit) { | |
hit.url = algoliaConfig.baseUrl + '/catalogsearch/result/?q=' + hit.query; | |
return algoliaConfig.autocomplete.templates.suggestions.render(hit); | |
} | |
} | |
}; | |
break; | |
} | |
} | |
return [sources, options]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment