-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.liquid
111 lines (98 loc) · 2.39 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{% comment %}
-- get all of the products in the shop (up to 25K), and their feature images if they exist
{% endcomment %}
{% assign cursor = nil %}
{% assign products_output = array %}
{% for n in (1..100) %}
{% capture query %}
query {
products(
first: 250
after: {{ cursor | json }}
sortKey: TITLE
) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
title
featuredImage {
url(
transform: {
maxWidth: 300
maxHeight: 300
crop: CENTER
}
)
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"products": {
"nodes": [
{
"id": "gid://shopify/Product/1234567890",
"title": "Widget",
"featuredImage": {
"url": "https://cdn.shopify.com/s/files/1/1234/5678/1234/products/widget_300x300_crop_center.jpg?v=1234567890"
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% comment %}
-- save the output for this product in an array
{% endcomment %}
{% for product in result.data.products.nodes %}
{% capture product_html %}
<li>
<b>{{ product.title }}</b>
<br>
{% if product.featuredImage %}
<img src="{{ product.featuredImage.url }}"/>
{% else %}
(no image)
{% endif %}
</li>
{% endcapture %}
{% assign products_output = products_output | push: product_html %}
{% endfor %}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.pageInfo.endCursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% comment %}
-- capture the HTML used by the PDF generator
{% endcomment %}
{% capture html %}
<h1>Product catalog</h1>
<ul>
{{ products_output | join: newline }}
</ul>
{% endcapture %}
{% comment %}
-- generate the PDF catalog, which will appear as a file download in the task run log
{% endcomment %}
{% action "files" %}
{
"catalog.pdf": {
"pdf": {
"html": {{ html | json }}
}
}
}
{% endaction %}