Smart Notifications
HomeContact SupportInstall via the App Store
  • Documentation
  • Getting Started
    • Pricing & Free Trial
    • Use Cases
    • Notification Outputs
    • Customer & Order Tags
    • Triggers & Filters
    • Mastering Rules
    • Immediate & Batch Notifications
    • Domain Mapping
  • Templates
    • Introduction
    • Email templates
      • Shopify Default Customer Order Notification
      • Shopify Default Merchant Order Notification
      • Batch Orders (multiple orders per email)
    • Attachment templates
      • Line Item Quantity Totals
      • Line Item Quantity Totals + Bundles
  • Help & Support
    • Contacting Support
    • Meet the Developer & Owner
  • Terms & Conditions
    • Terms of Service
    • Privacy Policy
    • Data Handling & Retention Policy
    • Fair Use Email Limits
Powered by GitBook
On this page
  • Template without line breaks
  • Template with line breaks
  1. Templates
  2. Attachment templates

Line Item Quantity Totals

This template counts the total quantity for each line item included in a batch of orders

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:

"Variant Title","Variant Quantity"
{% assign variant_list = '' %}{% for order in orders %}{% for line in order.line_items %}{% assign variant_list = variant_list | append: line.variant_id | append: '::' %}{% endfor %}{% endfor %}{% assign variant_list = variant_list | split: '::' | uniq  %}{% assign csv = '' %}{% 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 %}{% 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 %}{% comment %} Increment the variant count {% endcomment %}{% assign v_count = v_count | plus: line.quantity %}{% endif %}{% endfor %}{% endfor %}
{% assign csv = csv | append: '"' | append: variant_title | append: '","' | append: v_count | append: '"' %}{% endfor %}
{{ csv }}

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:

"Variant Title","Variant Quantity"
{% assign variant_list = '' %}
{% for order in orders %}
    {% for line in order.line_items %}
        {% assign variant_list = variant_list | append: line.variant_id | append: '::' %}
    {% endfor %}
{% endfor %}

{% assign variant_list = variant_list | split: '::' | uniq  %}
{% assign csv = '' %}
{% 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 %}
            {% 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 %}
            {% comment %} Increment the variant count {% endcomment %}
            {% assign v_count = v_count | plus: line.quantity %}
        {% endif %}
    {% endfor %}
{% endfor %}
{% assign csv = csv | append: '"' | append: variant_title | append: '","' | append: v_count | append: '"
' %}
{% endfor %}
{{ csv }}

PreviousAttachment templatesNextLine Item Quantity Totals + Bundles

Last updated 3 years ago