【问题标题】:Shopify: Tagging in cart and number of products in cartShopify:在购物车中标记和购物车中的产品数量
【发布时间】: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]” 第三:这个循环会遍历我购物车中的产品还是只是将它们组合在一起?我希望它循环并单独检查每个产品集。

谁能帮帮我?为什么我会收到语法错误?我还能做些什么来改进我的代码吗?

感谢您的帮助

【问题讨论】:

    标签: html shopify liquid


    【解决方案1】:

    回答您的问题:

    1. 您应该只需要一个结帐按钮,请参阅下面的代码。
    2. 你的内部for循环应该是{% for item in cart.items %},而不是{%for cart.items %}
    3. 见下面的代码。

    试试这样的:

    {% assign show_checkout_button = true %}
    {% for item in cart.items %}
      {% if item.product.tags contains 'SampleTag' and item.quantity <= 49 %}
        {% assign show_checkout_button = false %}
        <p>You will need to purchase more than 50 of the product "{{ item.product.title }}"</p>
      {% endif %}
    {% endfor %}
    {% if show_checkout_button %}
      <!-- show checkout button -->
    {% endif %}
    

    上述代码循环遍历购物车中的每个产品,如果产品有标签“SampleTag”且数量小于 50,则会显示错误消息而不是结帐按钮。

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多