Line Item Quantity Totals + Bundles
This template outputs the total quantity for each variant included in a batch of orders. In doing so it also includes bundle items created by Gazebo's Bundles app.

Template without line breaks

This version of the template can be cut 'n' pasted into the app's template editor and has had line breaks removed to ensure the CSV is properly formed:
1
"Variant Title", "SKU", "Quantity"
2
{% assign variant_list = '' %}{% for order in orders %}{% for line in order.line_items %}{% if line.bundle_items %}{% for bundle_item in line.bundle_items %}{% assign variant_list = variant_list | append: bundle_item.id | append: '::' %}{% endfor %}{% else %}{% assign variant_list = variant_list | append: line.variant_id | append: '::' %}{% endif %}{% endfor %}{% endfor %}{% assign variant_list = variant_list | split: '::' | uniq %}{% for v in variant_list %}{% assign v_count = 0 %}{% assign v_int = v | plus: 0 %}{% for order in orders %}{% for line in order.line_items %}{% if line.bundle_items %}{% for bundle_item in line.bundle_items %}{% assign variant_id_int = bundle_item.id | plus: 0 %}{% if v_int == variant_id_int %}{% assign variant_title = bundle_item.title %}{% assign variant_sku = bundle_item.sku %}{% comment %} Increment the variant count {% endcomment %}{% assign bundle_quantity_multiple = bundle_item.quantity | times: line.quantity %}{% assign v_count = v_count | plus: bundle_quantity_multiple %}{% endif %}{% endfor %}{% else %}{% assign variant_id_int = line.variant_id | plus: 0 %}{% if v_int == variant_id_int %}{% assign variant_title = line.product.title | append: ' - ' | append: line.variant.title %}{% assign variant_sku = line.variant.sku %}{% comment %} Increment the variant count {% endcomment %}{% assign v_count = v_count | plus: line.quantity %}{% endif %}{% endif %}{% endfor %}{% endfor %}"{{ variant_title }}","{{ variant_sku }}","{{ v_count }}"
3
{% endfor %}
Copied!

Template with line breaks

For those who want to use the template as a foundation and build their own CSV, this version with line breaks is much easier to read and work with:
1
"Variant Title", "SKU", "Quantity"
2
{% assign variant_list = '' %}
3
{% for order in orders %}
4
{% for line in order.line_items %}
5
{% if line.bundle_items %}
6
{% for bundle_item in line.bundle_items %}
7
{% assign variant_list = variant_list | append: bundle_item.id | append: '::' %}
8
{% endfor %}
9
{% else %}
10
{% assign variant_list = variant_list | append: line.variant_id | append: '::' %}
11
{% endif %}
12
{% endfor %}
13
{% endfor %}
14
15
{% assign variant_list = variant_list | split: '::' | uniq %}
16
17
{% for v in variant_list %}
18
{% assign v_count = 0 %}
19
{% assign v_int = v | plus: 0 %}
20
{% for order in orders %}
21
{% for line in order.line_items %}
22
{% if line.bundle_items %}
23
{% for bundle_item in line.bundle_items %}
24
{% assign variant_id_int = bundle_item.id | plus: 0 %}
25
{% if v_int == variant_id_int %}
26
{% assign variant_title = bundle_item.title %}
27
{% assign variant_sku = bundle_item.sku %}
28
{% comment %} Increment the variant count {% endcomment %}
29
{% assign bundle_quantity_multiple = bundle_item.quantity | times: line.quantity %}
30
{% assign v_count = v_count | plus: bundle_quantity_multiple %}
31
{% endif %}
32
{% endfor %}
33
{% else %}
34
{% assign variant_id_int = line.variant_id | plus: 0 %}
35
{% if v_int == variant_id_int %}
36
{% assign variant_title = line.product.title | append: ' - ' | append: line.variant.title %}
37
{% assign variant_sku = line.variant.sku %}
38
{% comment %} Increment the variant count {% endcomment %}
39
{% assign v_count = v_count | plus: line.quantity %}
40
{% endif %}
41
{% endif %}
42
{% endfor %}
43
{% endfor %}
44
"{{ variant_title }}","{{ variant_sku }}","{{ v_count }}"
45
46
{% endfor %}
Copied!