ajax - 如何在 ajax-cart-template.liquid 中获取产品变体及其标签的库存?
问题描述
我需要在我的购物车的“备注”字段中自动填写“预购”一词,只要库存小于零并且产品具有“预购”标签。
我已经尝试过使用此代码,但是在选择其他产品时它不会自动更新,可能是因为购物车与 ajax 一起使用
{% endraw %}
{% assign product_qty = 0 %}
{% for variant in product.variants %}
{% if variant.inventory_quantity <= 0 %}
{% if variant.selected %}
{% assign product_qty = variant.inventory_quantity %}
<p style="display:none">{{product_qty}}</p>
{% endif%}
{% assign product_qty = product_qty | plus: variant.inventory_quantity %}
{% endif %}
{% endfor %}
{% assign isTagAvailable = false %}
{% for item in cart.items %}
{% if item.product.tags contains 'pre-order1' %}
{% assign isTagAvailable = true %}
{% endif %}
{% endfor %}
{% if isTagAvailable == true and product_qty <= 0 %}
<div class="spec-instructions" style="display:none">
<label for="CartSpecialInstructions">Please leave special instructions below:</label>
<textarea name="note" class="input-full" id="CartSpecialInstructions">Pre-order {{ note }}
</textarea>
</div>
{% endif %}
{% raw %}
{% endraw %}{% if settings.cart_notes_enable %}{% raw %}
{% endraw %}{% endif %}{% raw %}
解决方案
推荐阅读
- selenium - Specflow 场景的参数范围
- c++ - 在对其执行多个操作后打印最终队列
- r - R中循环中的日期转换
- postgresql - 如何在 Postgres Enterprise Manager 工具中使用分析器?
- vba - VBA-将所选公式增加一行
- sql - 选择记录,其中日期 > 每一行的日期
- javascript - 带有串行端口的数据流和 Promise Node.js
- python - Odoo V10 - 视图的执行顺序?
- android - 数据绑定不支持合并标签问题的解决方法
- java - How to form where clause in jooq when filtering by user defined type