-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathscript.liquid
88 lines (81 loc) · 2.12 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
{% assign product_ids_and_titles = hash %}
{% assign cursor = nil %}
{% for n in (0..100) %}
{% capture query %}
query {
products(
first: 250
after: {{ cursor | json }}
sortKey: TITLE
query: {{ options.query | json }}
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
title
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"products": {
"pageInfo": {
"hasNextPage": false
},
"edges": [
{
"node": {
"id": "gid://shopify/Product/1234567890",
"title": "[sample product]"
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% for product_edge in result.data.products.edges %}
{% assign product_ids_and_titles[product_edge.node.id] = product_edge.node.title %}
{% endfor %}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.edges.last.cursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% if options.test_mode__boolean and options.live_mode__boolean %}
{% error "Please choose either test mode or live mode." %}
{% elsif options.test_mode__boolean == false and options.live_mode__boolean == false %}
{% error "Please choose either test mode or live mode." %}
{% elsif options.test_mode__boolean %}
{% log products_found_count: product_ids_and_titles.size, products_found: product_ids_and_titles %}
{% elsif options.live_mode__boolean %}
{% for keyval in product_ids_and_titles %}
{% action "shopify" %}
mutation {
productDelete(
input: {
id: {{ keyval[0] | json }}
}
) {
deletedProductId
userErrors {
field
message
}
}
}
{% endaction %}
{% endfor %}
{% endif %}