forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.liquid
85 lines (77 loc) · 2.35 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
{% assign csv = array %}
{% assign csv[0] = "Handle,Title,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,SKU,Quantity" | split: "," %}
{% assign cursor = nil %}
{% for n in (0..1000) %}
{% capture query %}
query {
products(
first: 15
after: {{ cursor | json }}
sortKey: CREATED_AT
query: {% if options.filter_by_product_type == blank %}null{% else %}{{ options.filter_by_product_type | json | prepend: "product_type:" | json }}{% endif %}
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
handle
title
variants(first: 30) {
edges {
node {
sku
inventoryQuantity
selectedOptions {
name
value
}
}
}
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% for product_edge in result.data.products.edges %}
{% assign product = product_edge.node %}
{% for variant_edge in product.variants.edges %}
{% assign variant = variant_edge.node %}
{% assign row = array %}
{% assign row[row.size] = product.handle %}
{% assign row[row.size] = product.title %}
{% assign row[row.size] = variant.selectedOptions[0].name %}
{% assign row[row.size] = variant.selectedOptions[0].value %}
{% assign row[row.size] = variant.selectedOptions[1].name %}
{% assign row[row.size] = variant.selectedOptions[1].value %}
{% assign row[row.size] = variant.selectedOptions[2].name %}
{% assign row[row.size] = variant.selectedOptions[3].value %}
{% assign row[row.size] = variant.sku %}
{% assign row[row.size] = variant.inventoryQuantity %}
{% assign csv[csv.size] = row %}
{% endfor %}
{% endfor %}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.edges.last.cursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{
"action": {
"type": "shopify",
"options": [
"create",
"metafield",
{
"namespace": "mechanic",
"key": "feed",
"type": "multi_line_text_field",
"value": {{ csv | csv | json }}
}
]
}
}