-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new task: send email notification when items are returned
- Loading branch information
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
docs/send-email-notification-when-items-are-returned/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Send email notification when items are returned | ||
|
||
Tags: Alert, Email, Returns | ||
|
||
Use this task to get an email alert with a list of the returned items whenever a return is marked as closed. | ||
|
||
* View in the task library: [tasks.mechanic.dev/send-email-notification-when-items-are-returned](https://tasks.mechanic.dev/send-email-notification-when-items-are-returned) | ||
* Task JSON, for direct import: [task.json](../../tasks/send-email-notification-when-items-are-returned.json) | ||
* Preview task code: [script.liquid](./script.liquid) | ||
|
||
## Default options | ||
|
||
```json | ||
{ | ||
"email_recipients__array_required": null | ||
} | ||
``` | ||
|
||
[Learn about task options in Mechanic](https://learn.mechanic.dev/core/tasks/options) | ||
|
||
## Subscriptions | ||
|
||
```liquid | ||
shopify/returns/close | ||
``` | ||
|
||
[Learn about event subscriptions in Mechanic](https://learn.mechanic.dev/core/tasks/subscriptions) | ||
|
||
## 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. | ||
|
||
## Installing this task | ||
|
||
Find this task [in the library at tasks.mechanic.dev](https://tasks.mechanic.dev/send-email-notification-when-items-are-returned), and use the "Try this task" button. Or, import [this task's JSON export](../../tasks/send-email-notification-when-items-are-returned.json) – see [Importing and exporting tasks](https://learn.mechanic.dev/core/tasks/import-and-export) to learn how imports work. | ||
|
||
## Contributions | ||
|
||
Found a bug? Got an improvement to add? Start here: [../../CONTRIBUTING.md](../../CONTRIBUTING.md). | ||
|
||
## Task requests | ||
|
||
Submit your [task requests](https://mechanic.canny.io/task-requests) for consideration by the Mechanic community, and they may be chosen for development and inclusion in the [task library](https://tasks.mechanic.dev/)! |
76 changes: 76 additions & 0 deletions
76
docs/send-email-notification-when-items-are-returned/script.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{% 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 { | ||
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 %} | ||
|
||
{% capture email_subject %}ALERT: New return {{ result.data.return.name }}{% endcapture %} | ||
|
||
{% capture email_body -%} | ||
Returned items | ||
============== | ||
{% for return_line_item in result.data.return.returnLineItems.nodes %} | ||
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,7 @@ | |
"Report", | ||
"Report Toaster", | ||
"Retention", | ||
"Returns", | ||
"Reviews", | ||
"Risk", | ||
"Sections", | ||
|
16 changes: 16 additions & 0 deletions
16
tasks/send-email-notification-when-items-are-returned.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"docs": "Use this task to get an email alert with a list of the returned items whenever a return is marked as closed.\n\nNote: this event will not occur when returns or exchanges are made via a POS terminal.", | ||
"halt_action_run_sequence_on_error": false, | ||
"name": "Send email notification when items are returned", | ||
"online_store_javascript": null, | ||
"options": { | ||
"email_recipients__array_required": null | ||
}, | ||
"order_status_javascript": null, | ||
"perform_action_runs_in_sequence": false, | ||
"preview_event_definitions": [], | ||
"script": "{% assign email_recipients = options.email_recipients__array_required %}\n\n{% if event.topic == \"shopify/returns/close\" %}\n {% capture query %}\n query {\n return(id: {{ return.admin_graphql_api_id | json }}) {\n name\n returnLineItems(first: 100) {\n nodes {\n quantity\n returnReason\n fulfillmentLineItem {\n lineItem {\n name\n sku\n }\n }\n }\n }\n }\n } \n {% endcapture %}\n \n {% assign result = query | shopify %}\n \n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"return\": {\n \"name\": \"#PREVIEW-R1\",\n \"returnLineItems\": {\n \"nodes\": [\n {\n \"quantity\": 1,\n \"returnReason\": \"STYLE\",\n \"fulfillmentLineItem\": {\n \"lineItem\": {\n \"name\": \"Widget - Chartreuse\",\n \"sku\": \"WDGT-CHRTRS\"\n }\n }\n }\n ]\n }\n }\n }\n }\n {% endcapture %}\n \n {% assign result = result_json | parse_json %}\n {% endif %}\n \n {% capture email_subject %}ALERT: New return {{ result.data.return.name }}{% endcapture %}\n\n {% capture email_body -%}\n Returned items\n ==============\n {% for return_line_item in result.data.return.returnLineItems.nodes %}\n Title: <strong>{{ return_line_item.fulfillmentLineItem.lineItem.name }}</strong>\n SKU: <strong>{{ return_line_item.fulfillmentLineItem.lineItem.sku }}</strong>\n Quantity: <strong>{{ return_line_item.quantity }}</strong>\n Reason: <strong>{{ return_line_item.returnReason }}</strong>\n {% endfor %}\n {% endcapture %}\n\n {% action \"email\" %}\n {\n \"to\": {{ email_recipients | json }},\n \"subject\": {{ email_subject | json }},\n \"body\": {{ email_body | newline_to_br | json }},\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n{% endif %}", | ||
"subscriptions": ["shopify/returns/close"], | ||
"subscriptions_template": "shopify/returns/close", | ||
"tags": ["Alert", "Email", "Returns"] | ||
} |