forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-copy-notes-from-customers-to-their-orders.json
20 lines (20 loc) · 2.67 KB
/
auto-copy-notes-from-customers-to-their-orders.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"docs": "Save time jumping between screens, by making sure that the order record has everything you need. Useful for shops that keep important fulfillment information in the customer notes. This task can be run manually to back-fill notes for open orders.\n\nThis task runs automatically, whenever a new order is created.\r\n\r\nRun this task manually to scan all open orders, copying the customer note to the order note. (To include open orders older than 60 days, [enable \"read all orders\"](https://help.usemechanic.com/tutorials/enabling-read_all_orders).)",
"halt_action_run_sequence_on_error": false,
"name": "Auto-copy notes from customers to their orders",
"online_store_javascript": null,
"options": {},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% capture newline %}\n{% endcapture %}\n\n{% if event.preview %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"update\",\n [\n \"order\",\n 12345\n ],\n {\n \"note\": \"(Note copied from customer)\"\n }\n ]\n }\n }\n{% elsif event.topic == \"shopify/orders/create\" %}\n {% if order.customer.note == blank %}\n {\"log\": \"No note on file for this customer; skipping order update\"}\n {% else %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"update\",\n [\n \"order\",\n {{ order.id | json }}\n ],\n {\n \"note\": {{ order.note | append: newline | append: newline | append: order.customer.note | strip | json }}\n }\n ]\n }\n }\n {% endif %}\n{% elsif event.topic == \"mechanic/user/trigger\" %}\n {% for order in shop.orders.open %}\n {% assign order_note_downcased = order.note | downcase %}\n {% assign customer_note_downcased = order.customer.note | downcase %}\n\n {% unless customer_note_downcased == blank or order_note_downcased contains customer_note_downcased %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"update\",\n [\n \"order\",\n {{ order.id | json }}\n ],\n {\n \"note\": {{ order.note | append: newline | append: newline | append: order.customer.note | strip | json }}\n }\n ]\n }\n }\n {% endunless %}\n {% endfor %}\n{% endif %}",
"subscriptions": [
"shopify/orders/create",
"mechanic/user/trigger"
],
"subscriptions_template": "shopify/orders/create\r\nmechanic/user/trigger",
"tags": [
"Customer Notes",
"Customers",
"Order Note"
]
}