forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
46 lines (42 loc) · 1.24 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
{% capture query %}
query {
customer(id: {{ customer.admin_graphql_api_id | json }}) {
id
events(first: 250) {
edges {
node {
attributeToUser
message
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% assign placed_event = result.data.first.last.events.edges | map: "node" | where: "attributeToUser" | first %}
{% assign name = placed_event.message | split: " created this " | first %}
{% assign tag_to_add = options.staff_names_and_tags__keyval_required[name] %}
{% if event.preview %}
{% assign name = options.staff_names_and_tags__keyval_required.first.first %}
{% assign tag_to_add = options.staff_names_and_tags__keyval_required.first.last %}
{% endif %}
{% if name == blank %}
{% log message: "No staff member detected.", customer: result.data.first.last %}
{% elsif tag_to_add == blank %}
{% log message: "No tag applicable for staff member.", staff_member: name %}
{% else %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ customer.admin_graphql_api_id | json }}
tags: {{ tag_to_add | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}