forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-tag-cancelled-orders.json
25 lines (25 loc) · 2.4 KB
/
auto-tag-cancelled-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
25
{
"docs": "This task watches for order cancellations, and adds or removes tags according to your preference. Run this task manually to update tags for existing cancelled orders.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag cancelled orders",
"online_store_javascript": null,
"options": {
"tags_to_add__array": [
"cancelled"
],
"tags_to_remove__array": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign orders = array %}\n\n{% if event.preview %}\n {% assign orders[0] = '{\"admin_graphql_api_id\": \"gid://shopify/Order/1234567890\", \"tags\": \"\"}' | parse_json %}\n{% elsif event.topic contains \"shopify/orders\" %}\n {% if order.cancelled_at != blank %}\n {% assign orders[0] = order %}\n {% endif %}\n{% elsif event.topic == \"mechanic/user/trigger\" %}\n {% assign orders = shop.orders.any.cancelled %}\n{% endif %}\n\n{% for order in orders %}\n {% assign order_tags = order.tags | split: \", \" %}\n\n {% assign tags_to_add = array %}\n {% assign tags_to_remove = array %}\n\n {% for tag in options.tags_to_add__array %}\n {% unless order_tags contains tag %}\n {% assign tags_to_add[tags_to_add.size] = tag %}\n {% endunless %}\n {% endfor %}\n\n {% for tag in options.tags_to_remove__array %}\n {% if order_tags contains tag %}\n {% assign tags_to_remove[tags_to_remove.size] = tag %}\n {% endif %}\n {% endfor %}\n\n {% if tags_to_add != empty or tags_to_remove != empty %}\n {% action \"shopify\" %}\n mutation {\n {% if tags_to_add != empty %}\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ tags_to_add | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n {% endif %}\n\n {% if tags_to_remove != empty %}\n tagsRemove(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ tags_to_remove | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n {% endif %}\n }\n {% endaction %}\n {% endif %}\n{% endfor %}",
"subscriptions": [
"shopify/orders/updated",
"mechanic/user/trigger"
],
"subscriptions_template": "shopify/orders/updated\nmechanic/user/trigger",
"tags": [
"Auto-Tag",
"Cancel",
"Orders"
]
}