Generate a report of orders that still require payment, with Mechanic.

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

Generate a report of orders that still require payment

This task generates a CSV spreadsheet, listing orders that are unpaid, partially paid, or pending payment. The resulting report is emailed to the recipient of your choice. Optionally, choose to have this report generated hourly, or daily.

Runs Occurs when a user manually triggers the task. Configuration includes include closed orders, recipient email address, email subject, email body, csv attachment filename, run hourly, and run daily.

15-day free trial – unlimited tasks

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/user/trigger

{% if options.run_hourly__boolean %}
  mechanic/scheduler/hourly
{% elsif options.run_daily__boolean %}
  mechanic/scheduler/daily
{% endif %}
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
include closed orders (boolean), recipient email address (email, required), email subject (required), email body (required, multiline), csv attachment filename (required), run hourly (boolean), run daily (boolean)
Code
{% assign orders = shop.orders %}

{% if options.include_closed_orders__boolean %}
  {% assign orders = orders.any %}
{% endif %}

{% assign orders_to_report = orders.unpaid | concat: orders.partially_paid | concat: orders.pending %}

{% if orders_to_report == empty and event.preview != true %}
  {% log "Zero orders found - skipping email. :)" %}
{% else %}
  {% assign rows = array %}
  {% assign header = array %}
  {% assign header[0] = "Order number" %}
  {% assign header[1] = "Date" %}
  {% assign header[2] = "Customer name" %}
  {% assign header[3] = "Order total" %}
  {% assign rows[0] = header %}

  {% for order in orders_to_report %}
    {% assign row = array %}
    {% assign row[0] = order.name %}
    {% assign row[1] = order.processed_at | date: "%F" %}
    {% assign row[2] = order.customer.first_name | append: " " | append: order.customer.last_name | strip %}
    {% assign row[3] = order.total_price | money_with_currency %}
    {% assign rows[rows.size] = row %}
  {% endfor %}

  {% action "email" %}
    {
      "to": {{ options.recipient_email_address__email_required | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__required_multiline | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }},
      "attachments": {
        {{ options.csv_attachment_filename__required | replace: ".csv", "" | append: ".csv" | json }}: {{ rows | csv | json }}
      }
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Include closed orders
true
Email subject
Orders that require payment: {{ "now" | date: "%F" }}
Email body
Hello,

Please find the attached report. Thanks!

-Mechanic, for {{ shop.name }}
CSV attachment filename
orders-that-require-payment-{{ "now" | date: "%Y%m%d" }}.csv