forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-email-when-an-order-is-tagged.json
29 lines (29 loc) · 4.83 KB
/
send-email-when-an-order-is-tagged.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"docs": "Use this task to monitor order tags, and notify staff, vendors, or any other interested parties when an order receives a certain tag. Useful for keeping teams across your business up to date as an order progresses.\n\nThis task monitors incoming orders, and updates to existing orders, looking for the tag of your choice. When the tag is detected, this task will send an email to the address(es) of your choice.\r\n\r\n**Important notes**\r\n\r\n* This task also adds a _second_ tag to the order when the email is sent, as a flag to mark the order as having had that email sent. This helps Mechanic remember what orders should _not_ have an email sent.\r\n* To help out merchants who have lots of existing orders, by default this task doesn't watch orders that were created _before_ you add this task to your Mechanic account.",
"halt_action_run_sequence_on_error": false,
"name": "Send email when an order is tagged",
"online_store_javascript": null,
"options": {
"tag_to_watch_for__required": "in-production",
"ignore_orders_that_are_older_than_this_task__boolean": true,
"email_recipients__array_required": [
],
"email_subject__required": "[{{shop.name}}] Order {{ order.name }}{% if order.customer.name %} placed by {{ order.customer.name }}{% endif %}",
"email_body__required_multiline": "Hello,\n\n{{ order.customer.name | default: 'Someone' }} placed a new order with your store, on {{ order.created_at | date: \"%b %d at %I:%M%P\" }}:\n<ul> {% for line in order.line_items %} <li> {{ line.quantity }}x {{ line.title }} {% if line.sku != \"\" %}(SKU: {{line.sku}}){% endif %} for {{ line.price | times: 100 | money }} each </li> {% endfor %} </ul>\nSubtotal: {{ order.subtotal_price | times: 100 | money }}\nTotal: {{ order.total_price | times: 100 | money }}\n{% if order.note != blank %}\nNote:\n{{ order.note }}\n{% endif %}\n\n<a href=\"https://{{ shop.domain }}/admin/orders/{{ order.id }}\">View order {{ order.name }}</a>\n{% if order.shipping_address %}\n<b>Shipping address:</b>\n{{ order.shipping_address.first_name }} {{ order.shipping_address.last_name }}\n{{ order.shipping_address.address1 }}\n{{ order.shipping_address.city }}, {{ shipping_address.province }} {{ shipping_address.zip }}\n{{ order.shipping_address.country }}\n{{ order.shipping_address.phone }}\n{% endif %}\nThanks,\n- Mechanic, for {{ shop.name }}"
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% comment %}\n Using a default value here, because an unsaved task doesn't yet have a created_at\n value, and we definitely need one for rendering preview actions.\n{% endcomment %}\n{% assign task_created_at = task.created_at | default: \"2020-01-01\" | date: \"%s\" %}\n\n{% if event.preview %}\n {% assign order = hash %}\n {% assign order[\"admin_graphql_api_id\"] = \"gid://shopify/Order/1234567890\" %}\n {% assign order[\"tags\"] = options.tag_to_watch_for__required %}\n {% assign order[\"created_at\"] = task_created_at | date: \"%s\" %}\n{% endif %}\n\n{% capture email_sent_tag %}{{ options.tag_to_watch_for__required }}-email-sent{% endcapture %}\n{% assign order_tags = order.tags | split: \", \" %}\n\n{% assign order_qualifies = false %}\n{% assign order_created_at = order.created_at | date: \"%s\" %}\n\n{% if options.ignore_orders_that_are_older_than_this_task__boolean and order_created_at < task_created_at %}\n {% log \"This order was created before this task was added to the store. Per the configured policy of this task, in order to avoid accidental emails for old and previously-tagged orders, this order will be ignored.\" %}\n{% elsif order_tags contains options.tag_to_watch_for__required %}\n {% unless order_tags contains email_sent_tag %}\n {% assign order_qualifies = true %}\n {% endunless %}\n{% endif %}\n\n{% assign email_recipients = options.email_recipients__array_required %}\n{% assign email_subject = options.email_subject__required %}\n{% assign email_body = options.email_body__required_multiline | strip | newline_to_br %}\n\n{% if order_qualifies %}\n {% action \"email\" %}\n {\n \"to\": {{ email_recipients | join: \", \" | json }},\n \"subject\": {{ email_subject | json }},\n \"body\": {{ email_body | json }},\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ email_sent_tag | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/orders/updated"
],
"subscriptions_template": "shopify/orders/updated",
"tags": [
"Email",
"Orders",
"Tag",
"Watch"
]
}