FROM CACHE - de_header

Must reload product page after changing variant

hennott
Tourist
18 0 3

Hi, I would like to assemble a text per variant depending on tags and stock. The code only works when loading the page, but not when changing the variants.

{% assign current_variant = product.selected_or_first_available_variant %}
{% if current_variant.inventory_quantity > 0 %}
 ... {{ current_variant.inventory_quantity }} ...
{% endif %}

How can I force the page to reload when changing the variant or how do I have to rewrite liquid? It also works somehow with the price.

2 ANTWORTEN 2

hennott
Tourist
18 0 3

After hours of searching .. this is my simple solution in the global.js

 

renderProductInfo() {
...
const destinationMYpart = document.getElementById(`mypart-${this.dataset.section}`);
const sourceMYpart = html.getElementById(`mypart-${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`);
        
if (sourceMYpart && destinationMYpart) destinationMYpart.innerHTML = sourceMYpart.innerHTML;
...

 where you can replace the "mypart" with your name. 

Gabe
Shopify Staff
16797 2658 3934

Hey @hennott 

 

Well done in finding a great solution which might help others here in the community too!

Gabe | Social Care @ Shopify
 - War meine Antwort hilfreich? Klicke Like um es mich wissen zu lassen! 
 - Wurde deine Frage beantwortet? Markiere es als Akzeptierte Lösung 
 - Um mehr zu erfahren, besuche das Shopify Help Center oder den Shopify Blog