Mechanic is a development platform for Shopify. :)
Useful when you discover that an order shouldn't have been fulfilled at all. :) After choosing an order tag in this task's configuration, add that tag to any order to have its fulfillments all cancelled, and the tag removed.
Runs when an order is updated and when user/orders/cancel_fulfillment is triggered. Configuration includes required order tag.
Useful when you discover that an order shouldn't have been fulfilled at all. :) After choosing an order tag in this task's configuration, add that tag to any order to have its fulfillments all cancelled, and the tag removed.
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.
Notes:
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
{% if event.topic == "shopify/orders/updated" %} {% if event.preview %} {% assign order = hash %} {% assign order["id"] = 1234567890 %} {% assign order["tags"] = options.required_order_tag__required %} {% assign order["admin_graphql_api_id"] = "gid://shopify/Order/1234567890" %} {% assign order["fulfillments"] = array %} {% assign order["fulfillments"][0] = hash %} {% assign order["fulfillments"][0]["id"] = 1234567890 %} {% assign order["fulfillments"][1] = hash %} {% assign order["fulfillments"][1]["id"] = 1234567890 %} {% endif %} {% assign order_tags = order.tags | split: ", " %} {% if order_tags contains options.required_order_tag__required %} {% assign cancellation_count = 0 %} {% for fulfillment in order.fulfillments %} {% if fulfillment.status == "cancelled" %} {% continue %} {% endif %} {% assign cancellation_count = cancellation_count | plus: 1 %} {% if cancellation_count == 1 %} {% action "shopify" %} [ "post", "/admin/orders/{{ order.id }}/fulfillments/{{ fulfillment.id }}/cancel.json", {} ] {% endaction %} {% else %} {% assign delay = 60 | times: cancellation_count %} {% action "event" %} { "topic": "user/orders/cancel_fulfillment", "task_id": {{ task.id | json }}, "run_at": {{ "now" | date: "%s" | plus: delay | json }}, "data": { "order_id": {{ order.id | json }}, "fulfillment_id": {{ fulfillment.id | json }} } } {% endaction %} {% endif %} {% endfor %} {% action "shopify" %} mutation { tagsRemove( id: {{ order.admin_graphql_api_id | json }} tags: {{ options.required_order_tag__required | json }} ) { userErrors { field message } } } {% endaction %} {% endif %} {% elsif event.topic == "user/orders/cancel_fulfillment" %} {% if event.preview %} {% assign event = hash %} {% assign event["data"] = hash %} {% assign event["data"]["order_id"] = 1234567890 %} {% assign event["data"]["fulfillment_id"] = 1234567890 %} {% endif %} {% action "shopify" %} [ "post", "/admin/orders/{{ event.data.order_id }}/fulfillments/{{ event.data.fulfillment_id }}/cancel.json", {} ] {% endaction %} {% endif %}