forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-tag-orders-by-discount-code.json
19 lines (19 loc) · 1.17 KB
/
auto-tag-orders-by-discount-code.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"docs": "This task watches for newly-created orders, and copies any discount codes present to the order's tags.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag orders by discount code",
"online_store_javascript": null,
"options": {},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.preview %}\n {% assign order = hash %}\n {% assign order[\"admin_graphql_api_id\"] = \"gid://shopify/Order/1234567890\" %}\n {% assign order[\"discount_codes\"] = array %}\n {% assign order[\"discount_codes\"][0] = hash %}\n {% assign order[\"discount_codes\"][0][\"code\"] = \"ABC123\" %}\n{% endif %}\n\n{% if order.discount_codes != blank %}\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ order.discount_codes | map: \"code\" | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/orders/create"
],
"subscriptions_template": "shopify/orders/create",
"tags": [
"Auto-Tag",
"Discounts",
"Orders"
]
}