Adding Custom attribute to all Searches in autocomplete

Hi, We have a Magento install that allows shoppers to select an area that are from and are then shown only products that are from that geographical area. Each product can only belong to one area, e.g. SHIPLEY , this is set in a product attribute.

We are using Algolia autocomplete search which is working fine. However I want to add the "area’ the customer is shopping in to the search so that it only returns products that have the customers shopping area set in the product area. I have added the attribute to the config in Magento backend so that it appears in my Algolia index default_products but I don’t know how to add this to the search “query” if you like.

Any help would be gratefully received

Regards

Matt

Hello Matt,

the search is done in autocomplete.js file and the data sources are defined in common.js file.

To modify the query, you’ll need to modify the products’ data source to refine results based on the area. And the correct area you mind define for example in configuration.phtml file if you don’t have it accessible in JS yet.

Is it doable for you?

Yes I think I can figure that out.

I was of thinking amending the indexer code to create a separate index for each area , e.g. products_default_AREANAME and then changing the index in the source to use whichever area the customer is using.

But I will try your way as then it is less changes to the core Magento extension

Thanks

Matt

1 Like

Just a follow up on this as I have just come across this again. To get the “area” into all searches I added it to the

$algoliaJSConfig

in

mypackage/mytheme/template/internals/configuration.phtml

and this then gets passed through to the search.

Thanks for your help and pointing me in the right direction.

Hello Matt,

thanks for letting me know.
I’m not sure on which version you are, but now you don’t have to override configuration.phtml, but you can update config array by algolia_after_create_configuration event. Here is where it’s called: https://github.com/algolia/algoliasearch-magento/blob/master/app/design/frontend/base/default/template/algoliasearch/internals/configuration.phtml#L292

Let me know if it would be a better way for you :slight_smile: