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.
Try this taskWhen it runs
Occurs when a user manually triggers the task
What you choose
- Include closed orders
- Recipient email address
- Email subject
Show 4 more
- Email body
- CSV attachment filename
- Run hourly
- Run daily
Task code and subscriptions
You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.
Subscriptions
mechanic/user/trigger
{% if options.run_hourly__boolean %}
mechanic/scheduler/hourly
{% elsif options.run_daily__boolean %}
mechanic/scheduler/daily
{% endif %}
How task subscriptions work
Option types and flags
- 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)
Task 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 %}
Mechanic Liquid reference
Default option values
- 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