Email a report of pick-up orders for the next x days, with Mechanic.

Mechanic is a development platform for Shopify. :)

Email a report of pick-up orders for the next x days

by Swati Swoboda (bhabus@gmail.com)

Using Zapiet to track store pickups? This task filters for orders that are tagged by Zapiet for pickup, and emails you a report of how many orders are scheduled for each of the next few days. Useful for scanning the week ahead, and blacking out dates that are at capacity.

Runs when a user triggers the task and every day at midnight. Configuration includes tagged with, date tag format, days ahead, email recipient, and email subject.

15-day free trial – unlimited tasks

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, 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.

Events
when a user triggers the task (mechanic/user/trigger)
every day at midnight (mechanic/scheduler/daily)
Options
tagged with (required), date tag format (required), days ahead (number, required), email recipient (email, required), email subject (required)
Script
{% assign tag_filter = options.tagged_with__required %}
{% assign date_tag_format = options.date_tag_format__required %}
{% assign days_ahead = options.days_ahead__number_required %}

{% assign seconds_per_day = 86400 %}
{% assign valid_dates = array %}
{% assign order_summary = hash %}

{% for i in (1..days_ahead) %}
  {% assign time_ahead = 0 | plus: seconds_per_day | times: i %}
  {% capture max_date %}{{'now' | date: "%s" | plus: time_ahead | date: date_tag_format }}{% endcapture %}
  {% assign valid_dates[valid_dates.size] = max_date %}
  {% assign order_summary[max_date] = 0 %}
{% endfor %}

{% if event.preview %}
  {% for tag_date in valid_dates %}
    {% assign not_so_random_num = tag_date | date: "%d" | plus: not_so_random_num %}
    {% assign order_summary[tag_date] = not_so_random_num %}
  {% endfor %}
{% else %}
  {% for order in shop.orders.unshipped %}
    {% assign order_tags = order.tags | split: ", " %}
    {% if order_tags contains tag_filter %}
       {% for tag_date in valid_dates %}
          {% if order_tags contains tag_date %}
              {% assign order_summary[tag_date] = order_summary[tag_date] | plus: 1 %}
            {% continue %}
          {% endif %}
       {% endfor %}
    {% endif %}
  {% endfor %}
{% endif %}

{% capture email_body %}
  Hi there,

  There are your orders tagged with `{{ tag_filter }}` for the next {{ days_ahead }} days:
  <ul>{% for tag_date in valid_dates %}<li>{{ tag_date | date: "%a, %b %d" }} - {{ order_summary[tag_date] }}</li>{% endfor %}</ul>

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

{% action "email" %}
  {
    "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 }}
  }
{% endaction %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Tagged with
Pickup Order
Date tag format
%d-%m-%Y
Days ahead
7
Email subject
Pickup orders by date