forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
37 lines (34 loc) · 994 Bytes
/
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
{% if event.preview %}
{% capture order_json %}
{
"admin_graphql_api_id": "gid://shopify/Order/12345",
"tags": "",
"note_attributes": {
{{ options.cart_attribute_to_monitor__required | json }}: "Hello!"
}
}
{% endcapture %}
{% assign order = order_json | parse_json %}
{% endif %}
{% assign order_tags = order.tags | split: ", " %}
{% assign attribute_name = options.cart_attribute_to_monitor__required %}
{% assign attribute_value = order.note_attributes[attribute_name] %}
{% if attribute_value == blank %}
{% log "Attribute is not present" %}
{% elsif order_tags contains attribute_value %}
{% log message: "Order is already tagged", tag: attribute_value %}
{% else %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ attribute_value | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}