-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathscript.liquid
78 lines (69 loc) · 2.53 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
77
78
{% if event.preview %}
{% assign order = '{"admin_graphql_api_id":"gid://shopify/Order/1234567890"}' | parse_json %}
{% assign order["email"] = "[email protected]" %}
{% assign order["tags"] = options.email_trigger_tag__required %}
{% endif %}
{% assign email_recipient = order.email %}
{% assign email_trigger_root = options.email_trigger_tag__required %}
{% assign email_trigger_root_to_match = email_trigger_root | downcase %}
{% assign email_sent_root = options.email_sent_tag__required %}
{% assign email_sent_root_to_match = email_sent_root | downcase %}
{% assign email_recipients = array %}
{% assign order_tags_to_add = array %}
{% assign order_tags_to_remove = array %}
{% assign order_tags = order.tags | downcase | split: ", " %}
{% for order_tag in order_tags %}
{% assign new_email_recipient = nil %}
{% assign parts = order_tag | downcase | split: ":" %}
{% if parts[0] == email_trigger_root_to_match %}
{% if parts.size == 1 %}
{% assign new_email_recipient = order.email %}
{% elsif parts[1] contains "@" %}
{% assign new_email_recipient = parts[1] %}
{% endif %}
{% endif %}
{% if new_email_recipient != blank %}
{% assign email_recipients[email_recipients.size] = new_email_recipient %}
{% assign order_tags_to_remove[order_tags_to_remove.size] = order_tag %}
{% assign order_tags_to_add[order_tags_to_add.size] = email_sent_root | append: ":" | append: new_email_recipient %}
{% endif %}
{% endfor %}
{% for email_recipient in email_recipients %}
{% action "email" %}
{
"to": {{ email_recipient | json }},
"subject": {{ options.email_subject__required | json }},
"body": {{ options.email_body_html__required_multiline_code | strip | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endfor %}
{% if order_tags_to_add != blank or order_tags_to_remove != blank %}
{% action "shopify" %}
mutation {
{% if order_tags_to_add != blank %}
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ order_tags_to_add | json }}
) {
userErrors {
field
message
}
}
{% endif %}
{% if order_tags_to_remove != blank %}
tagsRemove(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ order_tags_to_remove | json }}
) {
userErrors {
field
message
}
}
{% endif %}
}
{% endaction %}
{% endif %}