During the search/filtration process there are many event occurs where we might require to inject our frontend logic to change the default behaviour. Wizzy Magento 2 Extension provides frontend event hooks which can be implemented to modify the default behaviour or modify the parameters.
To see the supported event hooks, check the following file.
https://github.com/wizzy-ai/wizzy-search-magento-2/blob/dev/view/frontend/web/core/page.js
You can implement the event hooks in very simple steps,
- Inside Magento Admin Panel Go to Stores > Wizzy Search > Advanced Setup
- Select Yes in Overriding events.js (We’ve added this for developers to avoid creating new unnecessary layout files in their store theme core)
- Create new file module file under
app/design/frontend/Theme/Namespace/Wizzy_Search/web/events/events.js
Register Hook
In this file you can register any required hooks from the list to modify the config or the store behaviour. To register a hook use global wizzy variable and it’s function registerEvent. If you would like to use jQuery or any other library as dependency in these hooks implementation make sure you add them in requirejs.
Something like this,
requirejs(['jquery'], function($) { wizzy.registerEvent(wizzy.allowedEvents.AFTER_PRODUCTS_TRANSFORMED, function(products) { }); });
Notes:
- Register event takes 2 parameters. One is the event type and second is callback function.
- After modifying the given parameters from callback function you must return the same.