我们正在使用Shopify的'Order Printer‘应用程序制作发票。并且想要定制发票。例如,如果他们买了一本“书”--我们希望它写着“享受你的书”,如果是一张“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数组,以确定每种产品类型有多少个-并根据需要使用复数‘’输出其中一个/两个消息。
有什么想法吗?
发布于 2018-06-10 04:57:12
你走在了正确的轨道上,而不是限制,尽管你基本上想要计数。
{% 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}}
现在您有了一个count,您应该能够只对count数字执行if语句。
发布于 2018-06-23 02:35:45
感谢@trowse -解决了0的问题,这是由于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 %}
https://stackoverflow.com/questions/50758279
复制相似问题