-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.liquid
76 lines (68 loc) · 2.04 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 collection_created_at_s = collection.created_at | date: "%s" | times: 1 %}
{% assign collection_has_orders = false %}
{% assign cursor = nil %}
{% assign total_inventory = 0 %}
{% for n in (0..10000) %}
{% capture query %}
query {
orders(
first: 10
after: {{ cursor | json }}
sortKey: CREATED_AT
reverse: true
) {
edges {
node {
id
createdAt
lineItems(
first: 45
) {
edges {
node {
product {
inCollection(id: {{ collection.admin_graphql_api_id | json }})
}
}
}
}
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% for order_edge in result.data.orders.edges %}
{% assign order = order_edge.node %}
{% assign products_in_order = order.lineItems.edges | map: "node" | map: "product" %}
{% for product in products_in_order %}
{% if product.inCollection %}
{% assign collection_has_orders = true %}
{% break %}
{% endif %}
{% endfor %}
{% endfor %}
{% if collection_has_orders %}
{% break %}
{% endif %}
{% assign last_order_created_at_s = result.data.orders.edges.last.node.createdAt | date: "%s" | times: 1 %}
{% if last_order_created_at_s <= collection_created_at_s %}
{% break %}
{% endif %}
{% if result.data.orders.pageInfo.hasNextPage %}
{% assign cursor = result.data.orders.edges.last.cursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% if event.preview or collection_has_orders == false %}
{% action "email" %}
{
"to": {{ options.email_recipient__required_email | json }},
"subject": {{ options.email_subject__required | json }},
"body": {{ options.email_body__required_multiline | newline_to_br | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}