【发布时间】:2017-12-30 04:53:20
【问题描述】:
我有一个基于 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错误,所以我有点茫然!
【问题讨论】:
-
分享店面网址。确保它没有密码保护。
-
不幸的是,在网站完成之前,客户不允许我公开它。我知道这让事情变得更加困难,但我很乐意发布任何你想看看是否有帮助的代码?
标签: javascript shopify liquid