Adding an custom attribute to the instantsearch results


I’m trying to add a custom product to the instantsearch results. The custom attribute is per product so it would be necessary to add it to the algoliasearch/instantsearch/hit-item.phtml file.
I already indexed the custom attribute and I can see it on the Algolia Dashboard, but I don’t know how to get it fetched with the Algolia data and how to make it visible for each product in the results.

Any help is appreciated, thanks!

Hi Max,

I believe our magento extension retrieves all attributes by default. You can simply modify the hit-item.phtml file to display the new value or ideally create a customer extension to override it. It’s recommended as it won’t break when you upgrade the module. You can find a guide here for that:

Modifying the template directly it much easier but I’ll have to reapply the change after each update.

Hi @julienbourdeau

Thanks for your reply.
I’m sorry to say but it’s not simply editing the hit-item.phtml file. For example, I have to check if a parameter is set or not, it’s not clear anywhere how to do that using the Moustache templates. I had to add a backend observer to send the data to Algolia and with that, I was able to parse with the Moustache “conditionals”.

Now I’m trying to modify the sidebar filter since they keep parsing values even when there’s none set for the products, it says “No” on the filter, which means that the value is not set, so I’d expect to have it hidden.

But it’s not clear anywhere, sorry to say but the Algolia team seems to be abandoning the Magento 1.9.x Algolia extension, I posted a question here and on the Github repository long ago and I’m waiting for an answer from JanPetr since April.

So I don’t know, I’ll keep digging, if you know a better way to parse data coming from Algolia on the hit-item.phtml please send me an example. The same for the sidebar filters issue.

Thanks again.

Hi @max,
we’re sitting in the same boat I guess.
I think what you are doing should be fine. Patch any values in the observer before they are going to magento, the use the instant-hit overwrite to show them.
Additionally, I use a JS hook to patch the algolia results before they go to moustache. You can check (probably add a ?PageSpeed=off to see what’s going on, or go directly to )

Oh, and for attributes, I have a hacky php file which generates the backend admin config values for algolia in order to tell it which attributes to retrieve/search/index etc. Doing this manually is totally overkill for us.


1 Like

Hello @alex1

Thank you very much for your reply, I believe this clarifies a lot what I need to do, you saved the day!