Related Products guide doesn't reload related product list when clicked

I’m referring to the following guide: https://support.wix.com/en/article/corvid-adding-a-related-products-area-to-a-wix-store-product-page

I’ve implemented this and it is “working”. I put working in quotes because it’s not working exactly as one would expect: when you click one of the related products, the related products list doesn’t change even though the clicked product does load.

Only when I manually refresh the page will the related products list change.

The guide puts all of its code in the onReady state for the page. How do I make it so that the related products list is refreshed when one of the products in the list is clicked?

The guide doesn’t put all of it’s code through the onReady function.

Note that we don’t return the loadRelatedProducts result promise from $w.onReady. If we return a promise from $w.onReady, it will delay the page load until the promise is resolved. By not returning the promise, we allow the page to load as fast as possible while the related products load in the background.

What code have you used on the page, paste it up here so that other forum users can check it for you and suggest what can be done to fix your issue.

Akso, at the bottom of the tutorial there is this.

Next Steps

Open this example in the Editor to work with the template.
Publish the site and refresh your browser so the Stores collections appear in the Database.

So why not open up that provided example and see how the code is layed out already in the Wix Editor sample that Wix have provided for you.

Thanks for your response. The problem isn’t the code I used because I used exactly what is provided in the tutorial. The problem is in how Wix does the links in the related products list. When clicked, the page is not reloaded, it’s just “refetched” (I don’t know the proper term). So the code itself (that fetches the related products for the currently loaded product) doesn’t ever run again. That’s why you have to refresh the page to get the correct list of related products.

The example site in the Next Steps section has the same problematic behavior.

Having said all this, I was provided a solution through another forum. It is to add the following line in the $.onReady() block:

wixLocation.onChange( () => loadRelatedProducts() );

Okay first off, glad that you have found a solution to the issue.:+1:

However, it does seem strange that Wix would do all of that tutorial about adding related products, only for it not to work correctly and for it to need an additional line of code added to it.

Hopefully somebody like @yisrael-wix or a Wix Mod can read this post too and have a look at the tutorial to see if it does need changing and the code updated to suit.