-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathclean-up-draft-orders.json
24 lines (24 loc) · 2.86 KB
/
clean-up-draft-orders.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"docs": "Use this task to quickly delete draft orders from your account, optionally filtering by status, or by draft order age. Useful for keeping things tidy. :)",
"halt_action_run_sequence_on_error": false,
"name": "Clean up draft orders",
"online_store_javascript": null,
"options": {
"delete_open_draft_orders__boolean": null,
"delete_draft_orders_that_have_invoices_sent__boolean": null,
"delete_completed_draft_orders__boolean": null,
"minimum_draft_order_age_in_days__number": null,
"run_daily_at_midnight__boolean": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.preview %}\n {% if options.delete_open_draft_orders__boolean or options.delete_draft_orders_that_have_invoices_sent__boolean or options.delete_completed_draft_orders__boolean %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"delete\",\n [\n \"draft_order\",\n 1234567890\n ]\n ]\n }\n }\n {% else %}\n {\"error\": \"Please choose at least one draft order status to delete. :)\"}\n {% endif %}\n{% else %}\n {% assign maximum_created_at_s = nil %}\n {% if options.minimum_draft_order_age_in_days__number != blank %}\n {% assign minimum_draft_order_age_s = options.minimum_draft_order_age_in_days__number | times: 24 | times: 60 | times: 60 %}\n {% assign maximum_created_at_s = \"now\" | date: \"%s\" | minus: minimum_draft_order_age_s %}\n {% endif %}\n\n {% assign statuses = \"open,invoice_sent,completed\" | split: \",\" %}\n\n {% for status in statuses %}\n {% if status == \"open\" and options.delete_open_draft_orders__boolean != true %}\n {% continue %}\n {% elsif status == \"invoice_sent\" and options.delete_draft_orders_that_have_invoices_sent__boolean != true %}\n {% continue %}\n {% elsif status == \"completed\" and options.delete_completed_draft_orders__boolean != true %}\n {% continue %}\n {% endif %}\n\n {% for draft_order in shop.draft_orders[status] %}\n {% if maximum_created_at_s != nil %}\n {% assign draft_order_created_at_s = draft_order.created_at | date: \"%s\" | times: 1 %}\n {% if draft_order_created_at_s > maximum_created_at_s %}\n {% continue %}\n {% endif %}\n {% endif %}\n\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"delete\",\n [\n \"draft_order\",\n {{ draft_order.id | json }}\n ]\n ]\n }\n }\n {% endfor %}\n {% endfor %}\n{% endif %}",
"subscriptions": [
"mechanic/user/trigger"
],
"subscriptions_template": "mechanic/user/trigger\r\n{% if options.run_daily_at_midnight__boolean %}\r\n mechanic/scheduler/daily\r\n{% endif %}",
"tags": [
"Draft Orders",
"Orders"
]
}