forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-cancelled-orders-after-48-hours.json
19 lines (19 loc) · 2.15 KB
/
delete-cancelled-orders-after-48-hours.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"docs": "When an order is cancelled, this task waits 48 hours, and then permanently deletes the order. Simple as that! (Please note: if you only want to archive the cancelled order, not delete it, try a different task!)\n\nWhen an order is cancelled, this task waits 48 hours, and then permanently deletes the order. There is no undo for deleting an order, so make sure this is what you want!",
"halt_action_run_sequence_on_error": false,
"name": "Delete cancelled orders after 48 hours",
"online_store_javascript": null,
"options": {},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.topic == \"shopify/orders/updated\" %}\n {% assign cache_key = \"order-delete-scheduled-\" | append: order.id %}\n {% assign order_qualifies = false %}\n {% if order.cancelled_at != blank and cache[cache_key] == blank %}\n {% assign order_qualifies = true %}\n {% endif %}\n\n {% if event.preview or order_qualifies %}\n {\n \"action\": {\n \"type\": \"event\",\n \"options\": {\n \"topic\": \"user/orders/delete_cancelled\",\n \"data\": {\n \"order_id\": {{ order.id | json }}\n }\n }\n }\n }\n\n {\n \"action\": {\n \"type\": \"cache\",\n \"options\": {\n \"setex\": {\n \"key\": {{ cache_key | json }},\n \"value\": true,\n \"ttl\": {{ 60 | times: 60 | times: 48 }}\n }\n }\n }\n }\n {% endif %}\n{% elsif event.topic == \"user/orders/delete_cancelled\" %}\n {% assign order = shop.orders[event.data.order_id] %}\n {% if order.cancelled_at != blank or event.preview %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"delete\",\n [\n \"order\",\n {{ event.data.order_id | json }}\n ]\n ]\n }\n }\n {% endif %}\n{% endif %}",
"subscriptions": [
"shopify/orders/updated",
"user/orders/delete_cancelled+48.hours"
],
"subscriptions_template": "shopify/orders/updated\nuser/orders/delete_cancelled+48.hours",
"tags": [
"Delete",
"Orders"
]
}