【问题标题】:Big Cartel - hide all options if one option is out of stock大卡特尔 - 如果一个选项缺货,则隐藏所有选项
【发布时间】: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>

【问题讨论】:

    标签: ruby product bigcartel


    【解决方案1】:

    我会尝试以下方法。我没有测试以确保 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 %}
    

    【讨论】:

    • 我从没想过要做这样的变量赋值。谢谢你。这非常有效。
    猜你喜欢
    • 2018-07-17
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 2010-10-30
    • 1970-01-01
    相关资源
    最近更新 更多