skip to Main Content

We are producing Invoices with Shopify’s ‘Order Printer’ app.
and want to customise the Invoice.
For instance, if they have bought a ‘book’ – we want it to say “Enjoy your book”
and if a ‘CD’ – “Enjoy the music”.

I’ve found I can test the first item they purchased with ‘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 %}

But I would really like to scan the whole of the product.type array to determine how many of each product type there are – and output either/both messages – with plural ‘s’ as appropriate.

Any ideas?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks @trowse - solved the zeros issues, they were due to OrderPrinter cache problems and limitations. Just in case anyone needs it. Here's our solution:

    <!--  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 %}
    

  2. You’re on the right track instead of limiting though you basically want to count.

    {% 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}}
    

    Now that you have a count you should be able to just do an if statement of the count numbers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search