Sometimes you might find that the URL being generated for a product is broken or an unexpected value. You can add logs at different points in the code to catch the URL value that is being generated for a specific Magento product in your search results in order to find the source of the issue.
- The url_key is added to the attributes to select in the getProductCollectionQuery() method here: https://github.com/algolia/algoliasearch-magento-2/blob/develop/Helper/Entity/ProductHelper.php#L248
We pass the store_id on lines 224 and 225 which should assure that the correct store is filtered for the product collection.
Additionally, you can use the algolia_after_products_collection_build event at the end of the method where you can update the collection if you need to.
- The store_id is passed on the product itself again when we figure out which products have to be indexed/removed in the getProductsRecords() method here : https://github.com/algolia/algoliasearch-magento-2/blob/develop/Helper/Data.php#L502 and the record in finally created on line 535 with the getObject() method.
- In this method to add the url, we simply use the getUrlModel()->getUrl() method of the product entity, which is Magento native : https://github.com/algolia/algoliasearch-magento-2/blob/develop/Helper/Entity/ProductHelper.php#L491
So by tracing each of these steps you can find more details about the indexing process and how the URL is generated for a product.
Last reviewed 29-04-22.