Incorrect URLs are displayed in Auto Complete category results

We have a multi-store set-up, each site has a unique URL , the autocomplete menu for each site displays the correct products, but the URL’s in that are set for the categories point to a different store view.

@AlgoliaforMagento do you have any ideas why the url for the categories pages from another store in our multi-store setup would populate the Auto Complete results?

Hi @samuel1

OOTB our extension handles multi store URLs on Magento just fine.

You can test this yourself on a vanilla Magento install with our extension by creating multiple stores and going to Stores → Configuration → General → Web → Url Options and setting “Add Store Code to URLs” to “Yes”.

enter image description here

Reindex to Algolia and you should see the properly scoped URL (note the German store code de):
enter image description here

In an instance where the customer has distinct URLs for each storefront on a single Magento install (and is not just using something like store codes for localization) then a site builder will want to make sure that they have set the respective URLs for each store in their proper scope.

However, if they have already done that and it’s still not working then there is likely deeper investigation required.

And now for the gory details… :smirk:

URLs for locales / stores are configured per store scope and are pulled from the Magento StoreManager object (specifically: \Magento\Store\Model\StoreManager) which powers the URL model which is attached to the product pulled from the collection which is then serialized as JSON into Algolia.

What is noteworthy is that StoreManager is a singleton object that is injected via the Magento ObjectManager. What this means is that it is possible for other third party extensions to interfere with the way this works under the hood over the course of a single process and have a trickle down effect on our extension when it calls this object’s methods. (I’ve see this myself.)

The Algolia extension can only act on the information that Magento gives it - so in an instance like this you are looking at a case of “Garbage In Garbage Out”.

However, this must be properly debugged by a dev to really isolate something like this.

To determine why this is happening I highly recommend running XDebug against the CLI bin/magento indexer:reindex algolia_products . This is most likely where their URLs are getting jumbled - not in the front end.