Send email notification when items are returned
Use this task to get an email alert with a list of the returned items whenever a return is marked as closed.
Try this taskWhen it runs
Occurs whenever a return is closed
What you choose
Email recipients
Documentation
Use this task to get an email alert with a list of the returned items whenever a return is marked as closed.
Note: this event will not occur when returns or exchanges are made via a POS terminal.
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
shopify/returns/close
How task subscriptions work
Option types and flags
- Email recipients (array, required)
Task code
{% assign email_recipients = options.email_recipients__array_required %}
{% if event.topic == "shopify/returns/close" %}
{% capture query %}
query {
return(id: {{ return.admin_graphql_api_id | json }}) {
name
returnLineItems(first: 100) {
nodes {
... on ReturnLineItem {
quantity
returnReason
fulfillmentLineItem {
lineItem {
name
sku
}
}
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"return": {
"name": "#PREVIEW-R1",
"returnLineItems": {
"nodes": [
{
"quantity": 1,
"returnReason": "STYLE",
"fulfillmentLineItem": {
"lineItem": {
"name": "Widget - Chartreuse",
"sku": "WDGT-CHRTRS"
}
}
}
]
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign return_line_items = result.data.return.returnLineItems.nodes %}
{% if return_line_items == blank %}
{% log
message: "No verified return line items were found on this return.",
return: result.data.return
%}
{% break %}
{% endif %}
{% capture email_subject %}ALERT: New return {{ result.data.return.name }}{% endcapture %}
{% capture email_body -%}
Returned items
==============
{% for return_line_item in return_line_items %}
Title: <strong>{{ return_line_item.fulfillmentLineItem.lineItem.name }}</strong>
SKU: <strong>{{ return_line_item.fulfillmentLineItem.lineItem.sku }}</strong>
Quantity: <strong>{{ return_line_item.quantity }}</strong>
Reason: <strong>{{ return_line_item.returnReason }}</strong>
{% endfor %}
{% endcapture %}
{% action "email" %}
{
"to": {{ email_recipients | json }},
"subject": {{ email_subject | json }},
"body": {{ email_body | newline_to_br | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}
Mechanic Liquid reference