2017-07-24 57 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>