Send an email alert when a fulfillment is cancelled, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Send an email alert when a fulfillment is cancelled

by Isaac Bowen (team@usemechanic.com)

Useful for keeping an eye on unexpected cancellations by third party shipping services.

Runs when a fulfillment is updated. Configuration includes email recipient, email subject, and email body.

15-day free trial – unlimited tasks

Documentation

This task performs two actions: one to send an email, and one to "remember" that an email has been sent. (Without this second action, this task would send an email every time a cancelled fulfillment is updated.)

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 fulfillment is updated (shopify/fulfillments/update)
Options
email recipient (email, required), email subject (required), email body (multiline, required)
Script
{% assign fulfillment_qualifies = false %}
{% assign cache_key = task.id | append: fulfillment.id | sha256 %}

{% if fulfillment.status == "cancelled" and cache[cache_key] == blank %}
  {% assign fulfillment_qualifies = true %}
{% endif %}

{% if event.preview or fulfillment_qualifies %}
  {% action "email" %}
    {
      "to": {{ options.email_recipient__email_required | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__multiline_required | strip | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }}
    }
  {% endaction %}

  {% action "cache", "set", cache_key, true %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Email subject
A fulfillment for order {{ fulfillment.order.name | default: "an order" }} was cancelled
Email body
Hello,

A fulfillment with {{ fulfillment.line_items.size }} line item(s) was cancelled.

<a href="https://{{ shop.domain }}/admin/orders/{{ fulfillment.order.id }}">Manage this order in Shopify</a>

Thanks,
Mechanic, for {{ shop.name }}