Product recommendations returns false

EmanuelVT
Shopify Partner
16 2 8

So, this is a very strange issue happening in my theme's product-recommendations.liquid

 

recommendations.performed is returning false and recommendations.products_count is returning 0. With this, the section cannot load any recommended products in the products page. So, naturally I think that something is going wrong with the data-url of product-recommendations:

 

 

 

<product-recommendations class="product-recommendations page-width"
  data-url="{{ routes.product_recommendations_url }}?section_id={{ section.id }}&product_id={{ product.id }}&limit=4">

 

 

 I'm guessing this is returning null and that's why recommendation.performed is returning false. However, something strange is that, when I'm in Editor mode and I go to product recommendation, by default is not showing anything, recommendations.performed is false and recommendations.products_count is 0. However, when I hide the section and make it appear once again, product recommendation now works and I can see the products being recommended, recommendations.performed is true and recommendations.products_count is 4

 

recommendation.png

 

recommendation2.png

Of course, when I save it, it disappears, perfomed is false and count is 0 once again. So, this lets me see that at least the code that renders the recommended products is working. What's not working is how recommended-products is getting the data. 

 

My theory is this: I know recommendations.performed needs to know the id of the section where it's going to load and also the id of the product, otherwise, it returns false.  So, I think the product-recommendations section is actually loading first than the main-product page and that's why when it looks for the id of the section it can't find it, because it hasn't loaded yet and that's why it's returning false. In my example in the editor, when I toggle hidden to visible, the main-product page is completely loaded, so product-recommendations can find the section that it needs and loads the recommendations. But, when they both load at the same time (which is how is always going to work in the pov of the user) product-recommendations loads first and can't find what it needs to work properly. 

 

That's my working theory, I have no idea if it's true and if it is, I don't know how to fix it, but any help would be much appreciated. 

Reply 1 (1)

tirins007
Shopify Partner
1 0 0

Facing exact same issue. Did you manage to sort it out in the end?