forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-tag-new-orders-with-a-value-from-the-customer-note.json
22 lines (22 loc) · 2.3 KB
/
auto-tag-new-orders-with-a-value-from-the-customer-note.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "This task watches incoming orders, and tags each order with a certain value from the customer's note, as identified by a configurable prefix. For example, if your customers have notes resembling \"Username: xyz\", configure this task with the prefix \"Username: \" to have it tag incoming orders as \"xyz\". Useful with apps like inkFrog, which add eBay usernames to customer notes, using a prefix.\n\nThis task watches incoming orders, and tags each order with a certain value from the customer's note, as identified by a configurable prefix. For example, if your customers have notes resembling \"Username: xyz\", configure this task with the prefix \"Username: \" to have it tag incoming orders as \"xyz\".",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag new orders with a value from the customer note",
"online_store_javascript": null,
"options": {
"tag_prefix_in_customer_note__required": "eBay User:"
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.preview %}\n {% capture order_json %}\n {\n \"admin_graphql_api_id\": \"gid://shopify/Order/12345\",\n \"customer\": {\n \"note\": {{ options.tag_prefix_in_customer_note__required | append: \"abc123\" | json }}\n }\n }\n {% endcapture %}\n\n {% assign order = order_json | parse_json %}\n{% endif %}\n\n{% assign note_lines = order.customer.note | split: newline %}\n{% assign desired_prefix = options.tag_prefix_in_customer_note__required %}\n{% assign tag = nil %}\n\n{% for line in note_lines %}\n {% assign line_prefix = line | slice: 0, desired_prefix.size %}\n {% if line_prefix == desired_prefix %}\n {% assign tag = line | replace: line_prefix, \"\" %}\n {% endif %}\n{% endfor %}\n\n{% if tag != blank %}\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ tag | json }}\n ) {\n node {\n ... on Order {\n tags\n }\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",
"Customer Notes",
"Customers",
"Orders"
]
}