Events and Actions #
Finder allows interaction with its behavior through events and actions available via JavaScript. This enables you to listen to what happens in the search engine or even override certain default behaviors to adapt them to your store’s logic.
The following example shows how to register events and modify specific Finder actions:
(function() {
const initializerFinderActionsAndEvents = () => {
window.sbFinder.addEventListener('sellboostfinder:event:search:key-press', ({
key,
searchQuery
}) => {})
window.sbFinder.addActionHandler('sellboostfinder:action:search:failover', (searchQuery, redirectUrl) => {})
window.sbFinder.addActionHandler('sellboostfinder:action:cart:get-current', () => {
let quantity = 2
return new Promise(resolve => resolve(quantity))
})
window.sbFinder.addActionHandler('sellboostfinder:action:cart:add-product', (productId) => {
return new Promise(resolve => resolve(true))
})
}
if (window.sbFinder?.addActionHandler) {
initializerFinderActionsAndEvents()
} else {
window.addEventListener('sellboostfinder:event:loaded', () => initializerFinderActionsAndEvents())
}
})();
In this example, a block of code is initialized that runs when Finder is available. If the library is already loaded, it runs immediately; otherwise, it waits for the sellboostfinder:event:loaded event.
Within the initialization, several examples are shown:
- Key-press event: allows listening for when a user presses a key in the search field. The event provides information such as the key pressed and the current query.
- search:failover action: allows overriding the default behavior when a search fails or returns no results. This can be used, for example, to redirect to another page or apply custom logic.
- cart:get-current action: allows defining how to obtain the quantity of products currently in the store’s cart.
- cart:add-product action: allows defining the behavior when adding a product to the cart from Finder. The function must return a boolean value or a promise that resolves to a boolean indicating whether the action was successfully completed.
Configuration Variables #
Finder also allows modifying certain behaviors through global JavaScript variables that can be defined before the search engine loads.
- sbFinderDisabledStats: allows forcing the activation or deactivation of the statistics system.
- sbExcludedBrands: allows excluding specific brands from search results.
Example of use:
var sbFinderDisabledStats = false;
var sbExcludedBrands = [];
sbExcludedBrands.push("PENHALIGON'S");
sbExcludedBrands.push("ERBORIAN");
In this example, an array is defined with the brands that should not appear in the search results.
Custom JavaScript #
Finder allows loading custom JavaScript directly from the configuration panel. This option is available under the advanced configuration section of the Finder module.
From this section, you can add your own scripts to extend or modify the search engine’s behavior without needing to change the store theme code.
