2016-08-31 2 views
3

私はいくつかの他のものの中で、オプションの組み合わせが在庫切れの変形につながる場合、在庫切れとして表示するカートに追加ボタンを更新しようとしています。このコードでカートに追加ボタンの動作が更新されないのはなぜですか?

ドロップダウンメニューが変更されるとコードがトリガされます。価格は必要に応じて更新されているので、その部分が正常に動作していることがわかります。

しかし、私は最後に「else」がなぜその組み合わせが利用できないとしても、決して発射されないように見えるのは理解できません。

function letsDoThis() { 
     {% if product.options[0] %}var opt1 = document.getElementById('select-one').value;{% endif %} 
     {% if product.options[1] %}var opt2 = document.getElementById('select-two').value;{% endif %} 
     {% if product.options[2] %}var opt3 = document.getElementById('select-three').value;{% endif %} 
     var id = ''; 
     {% for v in product.variants %} 
     if(opt1=="{{ v.option1 }}"{% if product.options[1] %} && opt2=="{{ v.option2 }}"{% endif %}{% if product.options[2] %} && opt3=="{{ v.option3 }}"{% endif %}) { 
       var id = {{ v.id }}; 
       var price = "{{ v.price | money }}"; 
      } 
     {% endfor %} 
     if(id!='') { 
      document.getElementById('product-select').value = id; 
      document.getElementById('price').innerHTML = price; 
      document.getElementById('add').className += " enable-add"; 
     } else { 
      document.getElementById('product-select').value = ''; 
      document.getElementById('price').innerHTML = 'Unavailable'; 
      document.getElementById('add').className += " disable-add"; 
     } 

    } 

下の画像は、上記のコードに依存しているページの一部を示し:

Section of the page that this impacts...

+0

var id = "{{ v.id }}"は、あなたがして、ドロップダウンを作成するいずれかのShopifyのリンクオプションセレクタを使用するかを利用するselectCallbackにカスタムコードを追加するShopifyのOptionSelectorsを使用できない理由何らかの理由がありますすでにプラットフォームのために書かれているものは? このコードのトラブルシューティングを具体的に行うには、このコードがアクティブなサイトを共有できますか?スペルミスのクラス名やIDがどこかにある可能性があります。 –

+0

返信いただきありがとうございます。私はShopifyのOptionSelectorsを使って終わり、それを働かせました。私が避けていたのは、ドロップダウンのスタイルをカスタマイズするために使用していたプラグインsimpleselect.jsと競合していたからです。乾杯。 – Ben

答えて

0

これは、コードのバグであってもよいvar id = {{ v.id }}

8行に引用がない可能性があります。だから、今読んでいました:

function letsDoThis() { 
    {% if product.options[0] %}var opt1 = document.getElementById('select-one').value;{% endif %} 
    {% if product.options[1] %}var opt2 = document.getElementById('select-two').value;{% endif %} 
    {% if product.options[2] %}var opt3 = document.getElementById('select-three').value;{% endif %} 
    var id = ''; 
    {% for v in product.variants %} 
    if(opt1=="{{ v.option1 }}"{% if product.options[1] %} && opt2=="{{ v.option2 }}"{% endif %}{% if product.options[2] %} && opt3=="{{ v.option3 }}"{% endif %}) { 
      var id = "{{ v.id }}"; 
      var price = "{{ v.price | money }}"; 
     } 
    {% endfor %} 
    if(id!='') { 
     document.getElementById('product-select').value = id; 
     document.getElementById('price').innerHTML = price; 
     document.getElementById('add').className += " enable-add"; 
    } else { 
     document.getElementById('product-select').value = ''; 
     document.getElementById('price').innerHTML = 'Unavailable'; 
     document.getElementById('add').className += " disable-add"; 
    } 

} 
関連する問題