FROM CACHE - fr_header

Masquer automatiquement variants en rupture de stock

Yohan35
Touriste
4 0 1

Bonjour,

 

J'aimerais que les variants soient masqués automatiquement quand les stock tombe à 0.

Je travaille avec le thème envy.
Quelqu'un a t-il une solution ?

Merci pour votre aide,

 

Yohan.

5 RÉPONSES 5

droplearn
Shopify Partner
7 0 0

Bonjour

Si tu utilises l'application oberlo, tu peux le faire via les paramètres de l'application

Yohan35
Touriste
4 0 1
Bonjour,
Cela ne fonctionne que pour les produits achetés en drop shipping ?

##- Veuillez saisir votre réponse au-dessus de cette ligne -##

Fuznet
Shopify Expert
359 43 70

Bonjour,

Essayez de mettre ça à la fin de theme.js.liquid :

 

document.addEventListener('DOMContentLoaded', function() {
  const productJson = document.querySelectorAll('[id=ProductJson-<span class="dl">');
  if (productJson.length > 0) {
    for (let i = 0; i < productJson.length; i++) {
      const current = productJson[i];
      const sectionId = current.id.replace('ProductJson-', '');
      const section = document.querySelector('[data-section-id="' + sectionId + '"]');
      const product = JSON.parse(current.text);


      if (product.options.length === 1) {
        const unavailableVariants = [];


        for (let j = 0; j < product.variants.length; j++) {
          const variant = product.variants[j];


          if (!variant.available) {
            unavailableVariants.push(variant);
          }
        }


        if (unavailableVariants.length > 0) {
          const mutationCallback = function() {
            const variantOptions = section.querySelectorAll('.single-option-selector option');


            if (variantOptions.length > 0) {
              for (let k = 0; k < unavailableVariants.length; k++) {
                const unavailableVariant = unavailableVariants[k];


                for (let l = 0; l < variantOptions.length; l++) {
                  const option = variantOptions[l];


                  if (unavailableVariant.title === option.value) {
                    option.remove();
                  }
                }
              }


              if (typeof observer === 'object' && typeof observer.disconnect === 'function') {
                observer.disconnect();
              }
            }
          }


          const observer = new MutationObserver(mutationCallback);
          const addToCartForm = document.querySelector('form[action*="/cart/add"]');


          mutationCallback();


          if (window.MutationObserver && addToCartForm.length) {
            const config = { childList: true, subtree: true };


            if (typeof observer === 'object' && typeof observer.disconnect === 'function') {
              observer.disconnect();
            }


            observer.observe(addToCartForm, config);
          }
        }
      }
    }
  }
});
Yohan35
Touriste
4 0 1
Bonjour,

Je n'ai pas theme.js.liquid, mais juste theme.je dans assets. Et
malheureusement cela ne fonctionne pas ...
vera9
Visiteur
3 0 0

bonjour

 

Merci pour votre réponse,

est ce que ce code est compatible pour version DOWN 6.0.2 aussi s'il vous plait?

 

merci