Mechanic is a development and ecommerce automation platform for Shopify. :)
This task monitors for newly-created orders, and auto-tags any that were originally based on a Shopify draft order, using the tag of your choice.
Runs Occurs whenever an order is created. Configuration includes tag to add.
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, 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.
(By the way, have you seen our documentation? Have you joined the Slack community?)
shopify/orders/create
{% assign order_qualifies = false %}
{% if order.source_name == "shopify_draft_order" %}
{% assign order_qualifies = true %}
{% elsif order.source_name == "1830279" %}
{% comment %}
1830279 is the ID of the "Shopify Web" app. If we're seeing it here, it means that
the order was created via the /admin area.
{% endcomment %}
{% capture query %}
query {
order(id: {{ order.admin_graphql_api_id | json }}) {
app {
name
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"order": {
"app": {
"name": "Draft Orders"
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% if result.data.order.app.name == "Draft Orders" %}
{% assign order_qualifies = true %}
{% else %}
{% log message: "Order does not qualify",
order_source_name: order.source_name,
order_app_name: result.data.order.app.name %}
{% endif %}
{% else %}
{% log message: "Order does not qualify",
order_source_name: order.source_name %}
{% endif %}
{% if order_qualifies %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ order.admin_graphql_api_id | json }}
tags: {{ options.tag_to_add__required | json }}
) {
userErrors {
field
message
}
}
}
{% endaction %}
{% endif %}from-draft