forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
131 lines (118 loc) · 4.11 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{% if event.topic == "shopify/orders/paid" %}
{% if event.preview %}
{% assign order = hash %}
{% assign order["admin_graphql_api_id"] = "gid://shopify/Order/1234567890" %}
{% assign order["fulfillment_status"] = nil %}
{% endif %}
{% if order.fulfillment_status == blank or order.fulfillment_status == "partial" %}
{% assign one_day_in_seconds = 60 | times: 60 | times: 24 %}
{% assign days_to_wait = options.number_of_days_to_wait__number_required | default: 10 %}
{% assign days_to_wait_in_seconds = days_to_wait | times: one_day_in_seconds %}
{% assign run_at = "now" | date: "%s" | plus: days_to_wait_in_seconds %}
{% if options.only_send_reminders_on_weekdays__boolean %}
{% assign run_at_day = run_at | date: "%w" %}
{% if run_at_day == "0" %}{% comment %}-- Sunday --{% endcomment %}
{% assign run_at = run_at | plus: one_day_in_seconds %}
{% elsif run_at_day == "6" %}{% comment %}-- Saturday --{% endcomment %}
{% assign run_at = run_at | plus: one_day_in_seconds | plus: one_day_in_seconds %}
{% endif %}
{% endif %}
{% action "event" %}
{
"topic": "user/order/customer_reminder",
"task_id": {{ task.id | json }},
"run_at": {{ run_at | json }},
"data": {
"order_id": {{ order.admin_graphql_api_id | json }}
}
}
{% endaction %}
{% endif %}
{% elsif event.topic == "user/order/customer_reminder" %}
{% assign order_id = event.data.order_id %}
{% capture order_query %}
query {
order(id: {{ order_id | json }}) {
id
name
email
fullyPaid
displayFulfillmentStatus
cancelledAt
customer {
id
firstName
}
}
}
{% endcapture %}
{% assign order_result = order_query | shopify %}
{% if event.preview %}
{% capture order_result_json %}
{
"data": {
"order": {
"id": "gid://shopify/Order/1234567890",
"name": "#1234",
"email": "[email protected]",
"fullyPaid": true,
"displayFulfillmentStatus": "UNFULFILLED",
"cancelledAt": null,
"customer": {
"id": "gid://shopify/Customer/1234567890",
"firstName": "Charlie"
}
}
}
}
{% endcapture %}
{% assign order_result = order_result_json | parse_json %}
{% endif %}
{% assign order = order_result.data.order %}
{% if order.cancelledAt == blank and order.fullyPaid %}
{% if order.displayFulfillmentStatus == "UNFULFILLED" or order.displayFulfillmentStatus == "PARTIALLY_FULFILLED" %}
{% assign customer_first_name = order.customer.firstName | default: "there" %}
{% assign email_subject = options.email_subject__required | replace: "ORDER_NAME", order.name %}
{% assign email_body = options.email_body__multiline_required | strip | newline_to_br | replace: "CUSTOMER_FIRST_NAME", customer_first_name %}
{% action "email" %}
{
"to": {{ order.email | json }},
"subject": {{ email_subject | json }},
"body": {{ email_body | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% if options.tag_to_add_to_order != blank %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.id | json }}
tags: {{ options.tag_to_add_to_order | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% if options.tag_to_add_to_customer != blank %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.customer.id | json }}
tags: {{ options.tag_to_add_to_customer | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}