首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Shopify Liquid扫描订单-定制发票

如何使用Shopify Liquid扫描订单-定制发票
EN

Stack Overflow用户
提问于 2018-06-08 18:09:40
回答 2查看 70关注 0票数 0

我们正在使用Shopify的'Order Printer‘应用程序制作发票。并且想要定制发票。例如,如果他们买了一本“书”--我们希望它写着“享受你的书”,如果是一张“CD”--“享受音乐”。

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

代码语言:javascript
复制
{% 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数组,以确定每种产品类型有多少个-并根据需要使用复数‘’输出其中一个/两个消息。

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-10 04:57:12

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

代码语言:javascript
复制
{% 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语句。

票数 1
EN

Stack Overflow用户

发布于 2018-06-23 02:35:45

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

代码语言:javascript
复制
<!--  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 %}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50758279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档