To send a context for triggering a query rule in Magento, you can add logic to the searchFunction (which our extension uses by default), using the hook beforeInstantsearchInit
You can read about how to add this correctly in our frontend custom events documentation and learn more about the searchFunction in this supplemental documentation.
Here is an example implementation:
require(['algoliaCommon'], () => {
// Modify default `instantsearchOptions`
algolia.registerHook('beforeInstantsearchInit', function(instantsearchOptions, algoliaBundle)
{
var callbackSearchFunction = instantsearchOptions.searchFunction;
instantsearchOptions.searchFunction = function(helper) {
// Add your `searchFunction` methods here
// console.log("here is the helper state", helper.state);
helper.state.ruleContexts.push('your_rule_context');
console.log("after", helper.state);
callbackSearchFunction(helper);
}
return instantsearchOptions;
});
});