如何使用 Shopify 液体扫描订单 - 用于自定义发票



我们正在使用 Shopify 的"订单打印机"应用程序生成发票。 并希望自定义发票。 例如,如果他们买了一本书 - 我们希望它说"享受你的书" 如果是"CD" - "享受音乐"。

我发现我可以用"limit:1"测试他们购买的第一件商品:

{% for line_item in unfulfilled_line_items limit:1 %} 
productType: {{ line_item.product.type }} -   prodtype:{{product.type}} <br/>
{% if line_item.product.type contains "cd" %}
its a CD <br/>
{% else %}
it's not a CD?)<br/>
{% endif %}
{% endfor %}

但我真的很想扫描整个 product.type 数组,以确定每种产品类型有多少 - 并输出其中之一/两条消息 - 酌情使用复数"s"。

有什么想法吗?

你走在正确的轨道上,而不是限制,尽管你基本上想计数。

{% assign cd_count = 0 %}
{% assign book_count = 0 %}
{% for line_item in unfulfilled_line_items %}
{% if line_item.product.type == "cd" %}
{% assign cd_count = cd_count | plus: 1%}
{% endif %}
{% if line_item.product.type == "book" %}
{% assign book_count = book_count | plus: 1 %}
{% endif %}
{% endfor %}
cd count: {{ cd_count }}
book count: {{ book_count}}

现在你有一个计数,你应该能够只对计数数字做一个if语句。

谢谢@trowse - 解决了零问题,这是由于 OrderPrinter 缓存问题和限制造成的。 以防万一有人需要它。 以下是我们的解决方案:

<!--  count how many of each product type we are/have????? fullfilling -->
{% assign count_cd = 0 %}
{% assign count_bk = 0 %}
{% for line_item in unfulfilled_line_items %}
{% if line_item.product.type contains "cd" %}
{% assign count_cd = count_cd | plus:1 %} 
{% endif %}
{% if line_item.product.type  contains "Book" %}
{% assign count_bk = count_bk | plus:1 %} 
{% endif %}
{% endfor %}
<!--- end of counting -->
<!-- Enjoy.. message -->
{% if {{count_cd > 0 %}
Enjoy the music 
{% if {{count_bk > 0 %}
and the {{ count_bk | pluralize: 'book', 'books' }}<br/>
{% endif %}
{% else %}
{% if {{count_bk > 0 %}
Enjoy the {{ count_bk | pluralize: 'book', 'books' }}<br/>
{% endif %}
{% endif %}

最新更新