Email a summary of all products and quantities ordered, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Email a summary of all products and quantities ordered

Use this task to send yourself a quick tally of everything currently waiting in your order list. Super simple: just a list of products, and how many of each were ordered.

Runs Occurs every Monday at midnight (in local time) and Occurs when a user manually triggers the task. Configuration includes only include open orders, only include fully paid orders, only include fully unfulfilled orders, count quantities by variant instead of by product, email recipient, email subject, day of week to send email, and allow sending manually.

15-day free trial – unlimited tasks

Documentation

Use this task to send yourself a quick tally of everything currently waiting in your order list. Super simple: just a list of products, and how many of each were ordered.

This task will scan all of your orders, by default. Configure the task to only look at open, and/or fully paid, and/or fully unshipped orders. This task does not filter orders by when they were placed - only by their status.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/scheduler/{{ options.day_of_week_to_send_email__required | default: "monday" | downcase }}
{% if options.allow_sending_manually__boolean %}mechanic/user/trigger{% endif %}
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
only include open orders (boolean), only include fully paid orders (boolean), only include fully unfulfilled orders (boolean), count quantities by variant instead of by product (boolean), email recipient (email, required), email subject (required), day of week to send email (required), allow sending manually (boolean)
Code
{% assign orders = shop.orders.any %}
{% assign order_constraint_texts = array %}

{% if options.only_include_open_orders__boolean %}
  {% assign orders = orders.open %}
  {% assign order_constraint_texts[order_constraint_texts.size] = "open" %}
{% endif %}

{% if options.only_include_fully_paid_orders__boolean %}
  {% assign orders = orders.paid %}
  {% assign order_constraint_texts[order_constraint_texts.size] = "fully paid" %}
{% endif %}

{% if options.only_include_fully_unfulfilled_orders__boolean %}
  {% assign orders = orders.unshipped %}
  {% assign order_constraint_texts[order_constraint_texts.size] = "fully unshipped" %}
{% endif %}

{% assign quantities_by_line_item = hash %}
{% assign line_items = array %}

{% for order in orders %}
  {% for line_item in order.line_items %}
    {% if line_item.product_exists %}
      {% if options.count_quantities_by_variant_instead_of_by_product__boolean %}
        {% capture line_item_key %}<a href="https://{{ shop.domain }}/admin/products/{{ line_item.product.id }}/variants/{{ line_item.variant.id }}">{{ line_item.name }}</a>{% endcapture %}
      {% else %}
        {% capture line_item_key %}<a href="https://{{ shop.domain }}/admin/products/{{ line_item.product.id }}">{{ line_item.product.title }}</a>{% endcapture %}
      {% endif %}
    {% else %}
      {% assign line_item_key = line_item.title %}
    {% endif %}

    {% assign quantities_by_line_item[line_item_key] = quantities_by_line_item[line_item_key] | default: 0 | plus: line_item.quantity %}
    {% assign line_items[line_items.size] = line_item_key %}
  {% endfor %}
{% endfor %}

{% assign line_items = line_items | uniq | sort %}
{% assign list_items = array %}

{% for line_item in line_items %}
  {% capture list_item %}<li>{{ line_item }}: {{ quantities_by_line_item[line_item] }}</li>{% endcapture %}
  {% assign list_items[list_items.size] = list_item %}
{% endfor %}

{% if event.preview %}
  {% assign list_items[0] = "<li>Alpha: 5</li>" %}
  {% assign list_items[1] = "<li>Beta: 6</li>" %}
  {% assign list_items[2] = "<li>Gamma: 7</li>" %}
  {% assign list_items[3] = "<li>Delta: 8</li>" %}
{% endif %}

{% capture email_body %}
  Hi there,

  These are the products and ordered quantities, for all {{ order_constraint_texts | join: ", " }} orders:
  
  {{ list_items | join: "" }}

  Thanks,
  Mechanic (for {{ shop.name }})
{% endcapture %}

{
  "action": {
    "type": "email",
    "options": {
      "to": {{ options.email_recipient__email_required | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ email_body | unindent | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }}
    }
  }
}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Only include open orders
true
Email subject
Orders as of {{ "now" | date: "%Y-%m-%d" }}
Day of week to send email
Monday
Allow sending manually
true