【发布时间】:2017-01-11 03:32:15
【问题描述】:
我试图提出一个论点,如果产品页面上的任何产品选项已售罄,则不会显示添加到购物车按钮和选项下拉菜单,而是显示已售罄的 div。如果没有选项,那么它将显示添加到购物车按钮,如果产品有库存,但我不能让它工作。
我觉得我真的很亲近。如果产品没有选项,我已经能够使它工作,然后它会显示添加到卡按钮,如果产品售罄任何选项,它会显示“已售出”,但如果所有选项都有库存,它将显示选项选择器和添加到购物车按钮的次数与选项一样多 (例如:如果产品有 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>
【问题讨论】: