使用带有多个变量下拉列表的CartJS



我一直在让CartJS处理Shopify中的多个变体下拉列表。目前,每当我试图将产品添加到购物车时,它都会发出400(错误请求(。我猜是因为我的变体是空的。我当前的代码是:

{% for product_option in product.options_with_values %}
<label>
{{ product_option.name }}
<select>
{% for value in product_option.values %}
<option {% if product_option.selected_value == value %}selected{% endif %}>
{{ value }}
</option>
{% endfor %}
</select>
</label>
{% endfor %}

以及option_selector代码。

<script>
var selectCallback = function(variant, selector) {
timber.productPage({
money_format: "{{ shop.money_format }}",
variant: variant,
selector: selector
});
};
(function($) {
new Shopify.OptionSelectors('productSelect', {
product: {{ product | json }},
onVariantSelected: selectCallback,
enableHistoryState: true
});
// Add label if only one product option and it isn't 'Title'. Could be 'Size'.
{% if product.options.size == 1 and product.options.first != 'Title' %}
$('.selector-wrapper:eq(0)').prepend('<label for="productSelect-option-0">{{ product.options.first | escape }}</label>');
{% endif %}
// Hide selectors if we only have 1 variant and its title contains 'Default'.
{% if product.variants.size == 1 and product.variants.first.title contains 'Default' %}
$('.selector-wrapper').hide();
{% endif %}
});
</script>

链接选项可能是一种选择。

它匹配选择器(下拉菜单(中的值,以便获得正确的变体。

https://help.shopify.com/en/themes/customization/products/variants/link-product-options-in-menus

最新更新