Instantsearch sales badges

I can’t figure out how to make badges in the instantsearch results.

I’m running Magento v1 and usually I just compare the original price with price to figure out if a product is on sale or not, but now I have spent hours trying to figure this out in Algolia.

Could someone point me in the right direction please :stuck_out_tongue:

Paul

Hello @pal,

you’ll need to update the instant search page. Transform records’ data (InstantSearch.js hits doc) to see if you should display the badge and then you’ll need to override the template to actually display it.

I feel so stupid :smiley: I can’t wrap my head around it. To my defence I’m kind of a PHP guy and don’t really do much Javascript.

How to I get the price for each product (both the final price and original price) so that I can compare those and display the badge depending on the result. Do I have to get those in Javascript and send them to the template or can I access those from the template using some helper function or something?

Couldn’t a boolean field with a 1 or 0 for “sale” be added to an index, then use handlebar conditionals to display a badge?

Hello Pal, sorry for the late answer.

Both those prices should be indexed and retrieved during the search. You can use transformData method to compare those prices and create a new boolean attribute which would indicate if the badge should be displayed.

Then you’ll have to override the template with your own to add the badges.

All info you should find in documentation.

Let me know how it goes :slight_smile: