forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-add-default-custom-attributes-to-new-orders.json
22 lines (22 loc) · 2.25 KB
/
auto-add-default-custom-attributes-to-new-orders.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "Shopify allows orders to have custom attributes associated with them – and these attributes can be edited from within Shopify. Use this task to configure default attributes to be added to all new orders, providing an attribute name and (optionally) a value. Feel free to leave the value blank if you know you'll want to add your own values later, within Shopify.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-add default custom attributes to new orders",
"online_store_javascript": null,
"options": {
"default_order_attributes_to_add__keyval_required": {
"Assigned CSM": ""
}
},
"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[\"note_attributes\"] = array %}\n {% assign order[\"note_attributes\"][0] = hash %}\n {% assign order[\"note_attributes\"][0][\"name\"] = \"Existing attribute name\" %}\n {% assign order[\"note_attributes\"][0][\"value\"] = \"Existing attribute value\" %}\n{% endif %}\n\n{% assign attributes = array %}\n\n{% for pair in options.default_order_attributes_to_add__keyval_required %}\n {% assign attribute = hash %}\n {% assign attribute[\"key\"] = pair[0] %}\n {% assign attribute[\"value\"] = \"\" | append: pair[1] %}\n {% assign attributes[attributes.size] = attribute %}\n{% endfor %}\n\n{% for note_attribute in order.note_attributes %}\n {% assign attribute = hash %}\n {% assign attribute[\"key\"] = note_attribute.name %}\n {% assign attribute[\"value\"] = note_attribute.value %}\n {% assign attributes[attributes.size] = attribute %}\n{% endfor %}\n\n{% action \"shopify\" %}\n mutation {\n orderUpdate(\n input: {\n id: {{ order.admin_graphql_api_id | json }}\n customAttributes: {{ attributes | graphql_arguments }}\n }\n ) {\n order {\n customAttributes {\n key\n value\n }\n }\n userErrors {\n field\n message\n }\n }\n }\n{% endaction %}",
"subscriptions": [
"shopify/orders/create"
],
"subscriptions_template": "shopify/orders/create",
"tags": [
"Order Attributes",
"Orders"
]
}