-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-cancel-fulfillments-when-an-order-is-tagged.json
22 lines (22 loc) · 2.53 KB
/
auto-cancel-fulfillments-when-an-order-is-tagged.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "This task runs when an order is updated. When the tag of your choice is found in the order's tag list, all of its fulfillments (if any) will be cancelled, and the aforementioned tag will be removed.\n\nNotes:\n\n* If the configured tag is added to an order with no fulfillments, the tag _will_ be auto-removed, regardless.\n* If an older order happens to be updated, and it already has the configured tag, this task will process the order as if the tag was just added.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-cancel fulfillments when an order is tagged",
"online_store_javascript": null,
"options": {
"required_order_tag__required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n tags\n fulfillments {\n id\n status\n }\n }\n } \n{% endcapture %}\n\n{% assign result = query | shopify %}\n\n{% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"order\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"tags\": {{ options.required_order_tag__required | json }},\n \"fulfillments\": [\n {\n \"id\": \"gid://shopify/Fulfillment/1234567890\",\n \"status\": \"SUCCESS\"\n }\n ]\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% assign order = result.data.order %}\n\n{% if order.tags contains options.required_order_tag__required %}\n {% for fulfillment in order.fulfillments %}\n {% if fulfillment.status == \"CANCELLED\" %}\n {% continue %}\n {% endif %}\n\n {% action \"shopify\" %}\n mutation {\n fulfillmentCancel(id: {{ fulfillment.id | json }}) {\n fulfillment {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n {% endfor %}\n\n {% action \"shopify\" %}\n mutation {\n tagsRemove(\n id: {{ order.id | json }}\n tags: {{ options.required_order_tag__required | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/orders/updated"
],
"subscriptions_template": "shopify/orders/updated",
"tags": [
"Cancel",
"Fulfillment",
"Tag",
"Watch"
]
}