forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail-a-summary-of-all-products-and-quantities-ordered.json
29 lines (29 loc) · 4.26 KB
/
email-a-summary-of-all-products-and-quantities-ordered.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
25
26
27
28
29
{
"docs": "Use this task to send yourself a quick tally of everything currently waiting in your order list. Super simple: just a list of products, and how many of each were ordered.\n\nThis task will scan all of your orders, by default. Configure the task to only look at open, and/or fully paid, and/or fully unshipped orders. This task does not filter orders by when they were placed - only by their status.",
"halt_action_run_sequence_on_error": false,
"name": "Email a summary of all products and quantities ordered",
"online_store_javascript": null,
"options": {
"only_include_open_orders__boolean": true,
"only_include_fully_paid_orders__boolean": false,
"only_include_fully_unfulfilled_orders__boolean": false,
"count_quantities_by_variant_instead_of_by_product__boolean": false,
"email_recipient__email_required": "",
"email_subject__required": "Orders as of {{ \"now\" | date: \"%Y-%m-%d\" }}",
"day_of_week_to_send_email__required": "Monday",
"allow_sending_manually__boolean": true
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign orders = shop.orders.any %}\n{% assign order_constraint_texts = array %}\n\n{% if options.only_include_open_orders__boolean %}\n {% assign orders = orders.open %}\n {% assign order_constraint_texts[order_constraint_texts.size] = \"open\" %}\n{% endif %}\n\n{% if options.only_include_fully_paid_orders__boolean %}\n {% assign orders = orders.paid %}\n {% assign order_constraint_texts[order_constraint_texts.size] = \"fully paid\" %}\n{% endif %}\n\n{% if options.only_include_fully_unfulfilled_orders__boolean %}\n {% assign orders = orders.unshipped %}\n {% assign order_constraint_texts[order_constraint_texts.size] = \"fully unshipped\" %}\n{% endif %}\n\n{% assign quantities_by_line_item = hash %}\n{% assign line_items = array %}\n\n{% for order in orders %}\n {% for line_item in order.line_items %}\n {% if line_item.product_exists %}\n {% if options.count_quantities_by_variant_instead_of_by_product__boolean %}\n {% capture line_item_key %}<a href=\"https://{{ shop.domain }}/admin/products/{{ line_item.product.id }}/variants/{{ line_item.variant.id }}\">{{ line_item.name }}</a>{% endcapture %}\n {% else %}\n {% capture line_item_key %}<a href=\"https://{{ shop.domain }}/admin/products/{{ line_item.product.id }}\">{{ line_item.product.title }}</a>{% endcapture %}\n {% endif %}\n {% else %}\n {% assign line_item_key = line_item.title %}\n {% endif %}\n\n {% assign quantities_by_line_item[line_item_key] = quantities_by_line_item[line_item_key] | default: 0 | plus: line_item.quantity %}\n {% assign line_items[line_items.size] = line_item_key %}\n {% endfor %}\n{% endfor %}\n\n{% assign line_items = line_items | uniq | sort %}\n{% assign list_items = array %}\n\n{% for line_item in line_items %}\n {% capture list_item %}<li>{{ line_item }}: {{ quantities_by_line_item[line_item] }}</li>{% endcapture %}\n {% assign list_items[list_items.size] = list_item %}\n{% endfor %}\n\n{% if event.preview %}\n {% assign list_items[0] = \"<li>Alpha: 5</li>\" %}\n {% assign list_items[1] = \"<li>Beta: 6</li>\" %}\n {% assign list_items[2] = \"<li>Gamma: 7</li>\" %}\n {% assign list_items[3] = \"<li>Delta: 8</li>\" %}\n{% endif %}\n\n{% capture email_body %}\n Hi there,\n\n These are the products and ordered quantities, for all {{ order_constraint_texts | join: \", \" }} orders:\n \n {{ list_items | join: \"\" }}\n\n Thanks,\n Mechanic (for {{ shop.name }})\n{% endcapture %}\n\n{\n \"action\": {\n \"type\": \"email\",\n \"options\": {\n \"to\": {{ options.email_recipient__email_required | json }},\n \"subject\": {{ options.email_subject__required | json }},\n \"body\": {{ email_body | unindent | newline_to_br | json }},\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }}\n }\n }\n}",
"subscriptions": [
"mechanic/scheduler/monday",
"mechanic/user/trigger"
],
"subscriptions_template": "mechanic/scheduler/{{ options.day_of_week_to_send_email__required | default: \"monday\" | downcase }}\n{% if options.allow_sending_manually__boolean %}mechanic/user/trigger{% endif %}",
"tags": [
"Email",
"Inventory",
"Products"
]
}