-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-tag-a-customers-first-order.json
23 lines (23 loc) · 1.49 KB
/
auto-tag-a-customers-first-order.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"docs": "Watches for incoming orders that are the very first order on file for the related customer, and adds the tag of your choice.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-tag a customer's first order",
"online_store_javascript": null,
"options": {
"order_tag_to_add__required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"preview_event_definitions": [],
"script": "{% capture query %}\n query {\n customer(id: {{ order.customer.admin_graphql_api_id | json }}) {\n numberOfOrders\n }\n }\n{% endcapture %}\n\n{% assign result = query | shopify %}\n\n{% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"customer\": {\n \"numberOfOrders\": \"1\"\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% if result.data.customer.numberOfOrders == \"1\" %}\n {% action \"shopify\" %}\n mutation {\n tagsAdd(\n id: {{ order.admin_graphql_api_id | json }}\n tags: {{ options.order_tag_to_add__required | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% else %}\n {% log numberOfOrders: result.data.customer.numberOfOrders %}\n{% endif %}",
"subscriptions": [
"shopify/orders/create"
],
"subscriptions_template": "shopify/orders/create",
"tags": [
"Auto-Tag",
"Customers",
"Orders",
"Tag"
]
}