forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-tag-orders-based-on-cart-attributes.json
22 lines (22 loc) · 2.61 KB
/
auto-tag-orders-based-on-cart-attributes.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "Use this task to automatically categorize orders based on the cart attributes configured before checkout. Useful if you allow customers to supply extra information about their order, or if your cart has some hidden coding that adds cart attributes programatically.\n\nConfigure the \"Cart attribute to monitor\" option with the exact name of the cart attribute in use. This value is case-sensitive, and must include any punctuation used in the actual cart attribute.\r\n\r\nConfigure the \"Cart attribute values and order tags to add\" option with an attribute value on the left, and a tag on the right, to be applied when the left-hand value is found on an order. Add as many value/tag pairs as you like. :)",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag orders based on cart attributes",
"online_store_javascript": null,
"options": {
"cart_attribute_to_monitor__required": null,
"cart_attribute_values_and_order_tags_to_add__keyval_required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% comment %}\n Preferred order of options:\n\n {{ options.cart_attribute_to_monitor__required }}\n {{ options.cart_attribute_values_and_order_tags_to_add__keyval_required }}\n{% endcomment %}\n\n{% if event.preview %}\n {% capture order_json %}\n {\n \"admin_graphql_api_id\": \"gid://shopify/Order/12345\",\n \"tags\": \"\",\n \"note_attributes\": {\n {{ options.cart_attribute_to_monitor__required | json }}: {{ options.cart_attribute_values_and_order_tags_to_add__keyval_required.first.first | json }}\n }\n }\n {% endcapture %}\n\n {% assign order = order_json | parse_json %}\n{% endif %}\n\n{% assign attribute_name = options.cart_attribute_to_monitor__required %}\n{% assign attribute_value = order.note_attributes[attribute_name] %}\n{% assign tag = options.cart_attribute_values_and_order_tags_to_add__keyval_required[attribute_value] %}\n{% assign order_tags = order.tags | split: \", \" %}\n\n{% if tag == blank %}\n {% log \"Order does not qualify for a tag\" %}\n{% elsif order_tags contains tag %}\n {% log message: \"Order is already tagged\", tag: tag %}\n{% else %}\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ tag | 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",
"Cart Attributes",
"Orders"
]
}