-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.liquid
76 lines (65 loc) · 1.84 KB
/
script.liquid
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{% assign product_title = options.product_title__required %}
{% assign email_address = options.email_address__required %}
{% assign email_subject = options.email_subject__required %}
{% assign email_body = options.email_body__multiline_required %}
{% assign reply_to_email_address = options.reply_to_email_address %}
{% comment %}
-- requery the order in case a delay is configured in the task
{% endcomment %}
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
id
cancelledAt
lineItems(first: 250) {
nodes {
title
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"order": {
"id": "gid://shopify/Order/1234567890",
"lineItems": {
"nodes": [
{
"title": {{ product_title | json }}
}
]
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign order = result.data.order %}
{% comment %}
-- don't send notification email if the order has been cancelled
{% endcomment %}
{% if order.cancelledAt != blank %}
{% break %}
{% endif %}
{% comment %}
-- send notification email if any line item contains the configured product title
{% endcomment %}
{% for line_item in order.lineItems.nodes %}
{% if line_item.title == product_title %}
{% action "email" %}
{
"to": {{ email_address | json }},
"subject": {{ email_subject | json }},
"body": {{ email_body | strip | newline_to_br | json }},
"reply_to": {{ reply_to_email_address | default: shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% break %}
{% endif %}
{% endfor %}