-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathscript.liquid
86 lines (78 loc) · 2.17 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
{% assign orders = array %}
{% if event.topic contains "shopify/orders/" %}
{% if event.preview %}
{% assign order = hash %}
{% assign order["admin_graphql_api_id"] = "gid://shopify/order/1234567890" %}
{% assign order["tags"] = "" %}
{% endif %}
{% assign order_node = hash %}
{% assign order_node["id"] = order.admin_graphql_api_id %}
{% assign order_node["tags"] = order.tags | split: ", " %}
{% assign orders[0] = order_node %}
{% elsif event.topic == "mechanic/user/trigger" %}
{% capture bulk_operation_query %}
query {
orders {
edges {
node {
id
tags
}
}
}
}
{% endcapture %}
{% action "shopify" %}
mutation {
bulkOperationRunQuery(
query: {{ bulk_operation_query | json }}
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
{% endaction %}
{% elsif event.topic == "mechanic/shopify/bulk_operation" %}
{% if event.preview %}
{% capture objects_jsonl %}
{"id":"gid://shopify/order/1234567890","tags": []}
{% endcapture %}
{% assign bulkOperation = hash %}
{% assign bulkOperation["objects"] = objects_jsonl | parse_jsonl %}
{% endif %}
{% assign orders = bulkOperation.objects %}
{% endif %}
{% for order in orders %}
{% assign add_tag = false %}
{% assign remove_tag = false %}
{% if order.tags contains options.order_tag_to_watch__required %}
{% if order.tags contains options.order_tag_to_use_when_missing__required %}
{% assign remove_tag = true %}
{% endif %}
{% else %}
{% unless order.tags contains options.order_tag_to_use_when_missing__required %}
{% assign add_tag = true %}
{% endunless %}
{% endif %}
{% if add_tag or remove_tag %}
{% action "shopify" %}
mutation {
tags{% if add_tag %}Add{% else %}Remove{% endif %}(
id: {{ order.id | json }}
tags: {{ options.order_tag_to_use_when_missing__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}
{% endfor %}