【发布时间】:2020-11-20 16:04:44
【问题描述】:
我正在尝试编辑 Debut 主题以更好地满足我客户的需求。每当我在 product-template.liquid 文件中编辑变体选择器时,它都会引发错误并且不会将价格更新为正确的变体。
错误:
Uncaught TypeError: Cannot read property 'available' of undefined
at Product._initVariants (theme.js?v=785054923643579389:8098)
at new Product (theme.js?v=785054923643579389:8010)
at Sections._createInstance (theme.js?v=785054923643579389:47)
at Sections.<anonymous> (theme.js?v=785054923643579389:141)
at NodeList.forEach (<anonymous>)
at Sections.register (theme.js?v=785054923643579389:139)
at HTMLDocument.<anonymous> (theme.js?v=785054923643579389:9467)
原始代码是这样的(按预期完美运行):
<div class="product-form__controls-group">
{% for option in product.options_with_values %}
<div class="selector-wrapper js product-form__item">
<label for="SingleOptionSelector-{{ forloop.index0 }}" >
{{ option.name }}
</label>
<select class="single-option-selector single-option-selector-{{section.id }} product-form__input" id="SingleOptionSelector-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
我对此进行了编辑(我将两者分开,因为这是我的客户在他提出的设计中需要的):
<div class="product-form__controls-group">
<div class="selector-wrapper js product-form__item">
<label for="SingleOptionSelector-0">
Material
</label>
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input" id="SingleOptionSelector-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
{% for option in product.options_by_name['Material'].values %}
{% for value in option %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
{% endfor %}
</select>
</div>
<div class="selector-wrapper js product-form__item">
<label for="SingleOptionSelector-1">
Size
</label>
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input" id="SingleOptionSelector-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
{% for option in product.options_by_name['Size'].values %}
{% for value in option %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
{% endfor %}
</select>
</div>
</div>
如果有人可以帮助我,那就太棒了,因为 Shopify 论坛根本没有帮助。
【问题讨论】:
标签: shopify typeerror liquid variant