-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathemail-someone-when-certain-product-purchased.json
27 lines (27 loc) · 3.08 KB
/
email-someone-when-certain-product-purchased.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
{
"docs": "This task sends an email notification, immediately after an order is paid - if a product in the order has a title matching the product title you configure. Optionally, configure this task with a delay, in days, to wait before sending the email. (The task will not send any emails for orders that have since been cancelled.)",
"halt_action_run_sequence_on_error": false,
"name": "Email someone when a certain product is purchased",
"online_store_javascript": null,
"options": {
"product_title__required": null,
"email_address__required": null,
"email_subject__required": null,
"email_body__multiline_required": null,
"reply_to_email_address": null,
"number_of_days_to_wait_before_emailing__number": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign product_title = options.product_title__required %}\n{% assign email_address = options.email_address__required %}\n{% assign email_subject = options.email_subject__required %}\n{% assign email_body = options.email_body__multiline_required %}\n{% assign reply_to_email_address = options.reply_to_email_address %}\n\n{% comment %}\n -- requery the order in case a delay is configured in the task\n{% endcomment %}\n\n{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n cancelledAt\n lineItems(first: 250) {\n nodes {\n title\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 \"order\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"lineItems\": {\n \"nodes\": [\n {\n \"title\": {{ product_title | json }}\n }\n ]\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% assign order = result.data.order %}\n\n{% comment %}\n -- don't send notification email if the order has been cancelled\n{% endcomment %}\n\n{% if order.cancelledAt != blank %}\n {% break %}\n{% endif %}\n\n{% comment %}\n -- send notification email if any line item contains the configured product title\n{% endcomment %}\n\n{% for line_item in order.lineItems.nodes %}\n {% if line_item.title == product_title %}\n {% action \"email\" %}\n {\n \"to\": {{ email_address | json }},\n \"subject\": {{ email_subject | json }},\n \"body\": {{ email_body | strip | newline_to_br | json }},\n \"reply_to\": {{ reply_to_email_address | default: shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n\n {% break %}\n {% endif %}\n{% endfor %}\n",
"subscriptions": [
"shopify/orders/paid"
],
"subscriptions_template": "{% assign delay_days = options.number_of_days_to_wait_before_emailing__number %}\nshopify/orders/paid{% if delay_days != blank %}+{{ delay_days }}.days{% endif %}",
"tags": [
"Alert",
"Email",
"Orders",
"Products"
]
}