【发布时间】:2014-01-17 17:50:16
【问题描述】:
前几天我发了一个关于如何查看购物车中的商品是否有特定标签的问题,并得到了我的答案:
{% for item in cart.items %}
{% if item.product.tags contains 'SampleProduct' %}
<p>Enjoy your Product</p>
{% endif %}
{% endfor %}
此代码有效。但我想将它与检查购物车中的产品是否有一定数量的产品的代码结合起来。因此,例如,客户必须购买 50 件产品才能结账,而且他们会收到一条错误消息。这是我检查客户是否购买了足够商品的代码:
{% if cart.total_amount <= 49 %}
<p>You need to purchase 50 items or more to checkout</p>
{% else %}
{{include check out button}}
{% endif %}
所以我试着像这样一起使用这两个:
{% for item in cart.items %}
{% if item.product.tags contains 'SampleTag' %}
{%for cart.items %}
{% if product.item.total_amount <= 49 %}
<p> You will need to purchase more than 50 of this product </p>
{% else %}
*{{ Include Checkout button }}
{% endif %}
{% endfor %}
{% else %}
*{{ Include Checkout button }}
{% endif %}
{% endfor %}
*首先:我不知道我是否需要两个结帐按钮 第二:当我使用此代码时,我收到一条错误消息:“'for loop' 中的语法错误 - 有效语法:[collection] 中的 [item]” 第三:这个循环会遍历我购物车中的产品还是只是将它们组合在一起?我希望它循环并单独检查每个产品集。
谁能帮帮我?为什么我会收到语法错误?我还能做些什么来改进我的代码吗?
感谢您的帮助
【问题讨论】: