-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.liquid
76 lines (71 loc) · 1.92 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
{% assign metafield_namespace = options.metafield_namespace__required %}
{% assign metafield_key = options.metafield_key__required %}
{% assign customer = shop.customers[review.reviewer.external_id] %}
{% if event.preview %}
{% capture customer_json %}
{
"admin_graphql_api_id": "gid://shopify/Customer/1234567890",
"metafields": [
{
"namespace": {{ metafield_namespace | json }},
"key": {{ metafield_key | json }},
"value": 0
}
]
}
{% endcapture %}
{% assign customer = customer_json | parse_json %}
{% endif %}
{% if customer %}
{% assign current_review_count = customer.metafields[metafield_namespace][metafield_key].value | default: 0 %}
{% assign next_review_count = current_review_count | plus: 1 %}
{% assign next_review_count_as_string = next_review_count | append: "" %}
{% assign tag = options.tags_to_apply_for_review_counts__keyval[next_review_count_as_string] %}
{% action "shopify" %}
mutation {
metafieldsSet(
metafields: [
{
ownerId: {{ customer.admin_graphql_api_id | json }}
namespace: {{ metafield_namespace | json }}
key: {{ metafield_key | json }}
value: {{ next_review_count_as_string | json }}
type: "number_integer"
}
]
) {
metafields {
id
namespace
key
type
value
owner {
... on Customer {
id
}
}
}
userErrors {
code
field
message
}
}
{% if tag != blank %}
tagsAdd(
id: {{ customer.admin_graphql_api_id | json }}
tags: {{ tag | json }}
) {
node {
id
}
userErrors {
field
message
}
}
{% endif %}
}
{% endaction %}
{% endif %}