-
Notifications
You must be signed in to change notification settings - Fork 35
/
script.liquid
58 lines (54 loc) · 1.87 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
{% if event.preview %}
{% if options.delete_open_draft_orders__boolean or options.delete_draft_orders_that_have_invoices_sent__boolean or options.delete_completed_draft_orders__boolean %}
{
"action": {
"type": "shopify",
"options": [
"delete",
[
"draft_order",
1234567890
]
]
}
}
{% else %}
{"error": "Please choose at least one draft order status to delete. :)"}
{% endif %}
{% else %}
{% assign maximum_created_at_s = nil %}
{% if options.minimum_draft_order_age_in_days__number != blank %}
{% assign minimum_draft_order_age_s = options.minimum_draft_order_age_in_days__number | times: 24 | times: 60 | times: 60 %}
{% assign maximum_created_at_s = "now" | date: "%s" | minus: minimum_draft_order_age_s %}
{% endif %}
{% assign statuses = "open,invoice_sent,completed" | split: "," %}
{% for status in statuses %}
{% if status == "open" and options.delete_open_draft_orders__boolean != true %}
{% continue %}
{% elsif status == "invoice_sent" and options.delete_draft_orders_that_have_invoices_sent__boolean != true %}
{% continue %}
{% elsif status == "completed" and options.delete_completed_draft_orders__boolean != true %}
{% continue %}
{% endif %}
{% for draft_order in shop.draft_orders[status] %}
{% if maximum_created_at_s != nil %}
{% assign draft_order_created_at_s = draft_order.created_at | date: "%s" | times: 1 %}
{% if draft_order_created_at_s > maximum_created_at_s %}
{% continue %}
{% endif %}
{% endif %}
{
"action": {
"type": "shopify",
"options": [
"delete",
[
"draft_order",
{{ draft_order.id | json }}
]
]
}
}
{% endfor %}
{% endfor %}
{% endif %}