Big Cartel - 如果一个选项缺货,则隐藏所有选项

Big Cartel - hide all options if one option is out of stock

我试图提出一个论点,如果产品页面上的任何产品选项已售罄,则不会显示添加到购物车按钮和选项下拉列表,而会显示已售罄 div反而。如果没有选项,那么它会显示添加到购物车按钮,如果产品有库存,但我不能完全让它工作。

我觉得我真的很亲近。如果产品没有选项,我已经能够让它工作,然后它会显示添加到卡按钮,如果产品售完它显示的任何选项 'Sold',但如果所有选项都有库存,它会显示选项选择器并添加到购物车按钮的次数与选项的次数一样多 (例如:如果产品有 2 个选项,页面将显示:

选项选择器
添加到购物车按钮
选项选择器
添加到购物车按钮)

{% when 'active' %}
<form id="product-form" method="post" action="/cart">
{% for option in product.options %}

{% if product.has_default_option %}

{{ product.option | hidden_option_input }}

<button class="button" id="product-addtocart" name="submit"    
type="submit">Add to cart</button>

{% endif %}

{% if option.sold_out %}

{{ product.option | hidden_option_input }}
    <div class="sold">
      <h4><span>Sold</span></h4>
    </div>
{% endif %}
{% if option.sold_out == false %}

<div id="product-options" class="options">
{{ product.options | options_select }}
</div><br>
<button class="button" id="product-addtocart" name="submit"    
type="submit">Add to cart</button>

{% endif %}

{% endfor %}
{% if product.on_sale %}<div>On Sale</div>{% endif %}   
</form>

我会尝试以下操作。我没有测试以确保 has_default_option 条件设置正确,但这只是为了说明使用变量赋值 (inStock) 跟踪股票的想法。

{% assign inStock = true %}
{% for option in product.options %}
    {% if option.sold_out %}
        {% assign inStock = false %}
    {% endif %}
{% endfor %}

{% if inStock %}
    <form id="product-form" method="post" action="/cart">
        {% if product.has_default_option %}
            {{ product.option | hidden_option_input }}
        {% else %}
            <div id="product-options" class="options">
                {{ product.options | options_select }}
            </div>
        {% endif %}
        <button class="button" id="product-addtocart" name="submit" type="submit">Add to cart</button>
        {% if product.on_sale %}<div>On Sale</div>{% endif %}
    </form>
{% else %}
    <div class="sold">
        <h4><span>Sold</span></h4>
    </div>
{% endif %}