-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsend-an-email-alert-if-a-new-collection-has-no-orders-after-x-days.json
24 lines (24 loc) · 3.39 KB
/
send-an-email-alert-if-a-new-collection-has-no-orders-after-x-days.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"docs": "This task watches for newly-created collections, waits a configurable number of days, and then sends a staff email if no orders have been placed for products that are in the new collection.",
"halt_action_run_sequence_on_error": false,
"name": "Send an email alert if a new collection has no orders after x days",
"online_store_javascript": null,
"options": {
"email_recipient__required_email": "",
"email_subject__required": "The new collection \"{{ collection.title }}\" has no orders yet",
"email_body__required_multiline": "Hello,\n\nThe collection \"<a href=\"https://{{ shop.domain }}/collections/{{ collection.handle }}\">{{ collection.title }}</a>\" was created on {{ collection.created_at | date: \"%Y-%m-%d\" }}, and no orders have yet been made for products in this collection.\n\nThanks,\nMechanic, for {{ shop.name }}",
"days_to_wait_before_checking__number_required": "2"
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign collection_created_at_s = collection.created_at | date: \"%s\" | times: 1 %}\n{% assign collection_has_orders = false %}\n\n{% assign cursor = nil %}\n{% assign total_inventory = 0 %}\n\n{% for n in (0..10000) %}\n {% capture query %}\n query {\n orders(\n first: 10\n after: {{ cursor | json }}\n sortKey: CREATED_AT\n reverse: true\n ) {\n edges {\n node {\n id\n createdAt\n lineItems(\n first: 45\n ) {\n edges {\n node {\n product {\n inCollection(id: {{ collection.admin_graphql_api_id | json }})\n }\n }\n }\n }\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = query | shopify %}\n\n {% for order_edge in result.data.orders.edges %}\n {% assign order = order_edge.node %}\n {% assign products_in_order = order.lineItems.edges | map: \"node\" | map: \"product\" %}\n {% for product in products_in_order %}\n {% if product.inCollection %}\n {% assign collection_has_orders = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n {% endfor %}\n\n {% if collection_has_orders %}\n {% break %}\n {% endif %}\n\n {% assign last_order_created_at_s = result.data.orders.edges.last.node.createdAt | date: \"%s\" | times: 1 %}\n {% if last_order_created_at_s <= collection_created_at_s %}\n {% break %}\n {% endif %}\n\n {% if result.data.orders.pageInfo.hasNextPage %}\n {% assign cursor = result.data.orders.edges.last.cursor %}\n {% else %}\n {% break %}\n {% endif %}\n{% endfor %}\n\n{% if event.preview or collection_has_orders == false %}\n {% action \"email\" %}\n {\n \"to\": {{ options.email_recipient__required_email | json }},\n \"subject\": {{ options.email_subject__required | json }},\n \"body\": {{ options.email_body__required_multiline | newline_to_br | json }},\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/collections/create+2.days"
],
"subscriptions_template": "shopify/collections/create+{{ options.days_to_wait_before_checking__number_required | default: 2 }}.days",
"tags": [
"Collections",
"Email",
"Products"
]
}