2017-07-24 52 views
1

我有一個建立在Shopify Slate之上的主題。我所有的產品都有不同的尺寸和顏色。這些作爲兩個選擇元素在頁面上輸出 - 一個用於大小,一個用於顏色。當我從這兩個選擇中選擇選項並將我的產品添加到購物車時,它總是添加默認變體。Shopify Slate變體不更新

這是在我的product.liquid部分所述變體的代碼:

{% unless product.has_only_default_variant %} 
    {% for option in product.options_with_values %} 
     <div class="selector-wrapper js"> 
      <label for="SingleOptionSelector-{{ forloop.index0 }}"> 
       {{ option.name }} 
      </label> 

      <select id="SingleOptionSelector-{{ forloop.index0 }}" 
      class="single-option-selector" data-single-option-selector data-index="option{{ option.position }}"> 
       {% for value in option.values %} 
        <option 
         value="{{ value | escape }}" 
         {% if option.selected_value == value %}selected="selected"{% endif %}> 
         {{ value }} 
        </option> 
       {% endfor %} 
      </select> 
     </div> 
    {% endfor %} 
{% endunless %} 

<select name="id" class="" data-product-select> 
    {% for variant in product.variants %} 
     <option 
     {% if variant == current_variant %}selected="selected"{% endif %} 
     {% unless variant.available %}disabled="disabled"{% endunless %} 
     value="{{ variant.id }}"> 
      {{ variant.title }} 
     </option> 
    {% endfor %} 
</select> 

通過variant.js和product.js代碼的外觀上來看,從前兩個選擇的值都應該被用來更新最後一個,但由於某種原因,這沒有發生。這兩個文件中的代碼沒有改變,我沒有在控制檯中發現任何JS錯誤,所以我有些失落!

+0

份額店面網址。確保它沒有密碼保護。 –

+0

不幸的是客戶不會讓我公佈它,直到網站完成。我意識到這會讓事情變得更加困難,但我很高興發佈任何您想查看的代碼,看看是否有幫助? – Infobahn

回答

0

確保您的整個部分(除schema)被包裹在

<div data-section-id="{{ section.id }}" data-section-type="product" data-enable-history-state="true" itemscope itemtype="http://schema.org/Product"> 

和你通過產品對象的JSON石板腳本

<script type="application/json" data-product-json> 
     {{ product | json }} 
</script>