forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-invite-customers-after-an-order.json
28 lines (28 loc) · 5.5 KB
/
auto-invite-customers-after-an-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
24
25
26
27
28
{
"docs": "Automatically prompt customers to activate their customer accounts, after placing an order in your store, by triggering a customizable Shopify-powered email. Useful if your online store unlocks special offers, functionality, or content after making a purchase. Optionally, only send invitations if the customer has ordered a product with a specific tag.\n\nThis task works by asking Shopify to send along an invitation email, using the subject and body that you configure here. The email will use your Shopify account's \"Customer account invite\" email template, available in the \"Notifications\" area of your Shopify settings. Note: Because this task triggers a Shopify-powered email, and because this email already uses a Shopify template, the actual message body is optional. (If provided, HTML and CSS are not supported.) And, there's no need to add in an invitation link yourself – this will be taken care of by the Shopify email template as well.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-invite customers after an order",
"online_store_javascript": null,
"options": {
"only_invite_if_the_customer_has_not_yet_been_invited__boolean": false,
"only_invite_if_the_customer_has_this_tag": "",
"only_invite_if_the_order_contains_a_product_with_this_tag": "",
"custom_invitation_email_subject": "",
"custom_invitation_email_message__multiline": "",
"invitation_email_bcc__array": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"preview_event_definitions": [],
"script": "{% comment %}\n Establish option order:\n {{ options.only_invite_if_the_customer_has_not_yet_been_invited__boolean }}\n {{ options.only_invite_if_the_customer_has_this_tag }}\n {{ options.only_invite_if_the_order_contains_a_product_with_this_tag }}\n {{ options.custom_invitation_email_subject }}\n {{ options.custom_invitation_email_message__multiline }}\n {{ options.invitation_email_bcc__array }}\n{% endcomment %}\n\n{% if event.preview %}\n {% assign order = hash %}\n {% assign order[\"customer\"] = hash %}\n {% assign order[\"customer\"][\"state\"] = \"disabled\" %}\n\n {% if options.only_invite_if_the_customer_has_this_tag != blank %}\n {% assign order[\"customer\"][\"tags\"] = options.only_invite_if_the_customer_has_this_tag %}\n {% endif %}\n\n {% if options.only_invite_if_the_order_contains_a_product_with_this_tag != blank %}\n {% capture line_items_json %}\n [\n {\n \"product\": {\n \"tags\": {{ options.only_invite_if_the_order_contains_a_product_with_this_tag | json }}\n }\n }\n ]\n {% endcapture %}\n {% assign order[\"line_items\"] = line_items_json | parse_json %}\n {% endif %}\n{% endif %}\n\n{% assign customer_qualifies = true %}\n{% if order.customer == nil or order.customer.state == \"enabled\" %}\n {% assign customer_qualifies = false %}\n{% elsif options.only_invite_if_the_customer_has_not_yet_been_invited__boolean and order.customer.state == \"invited\" %}\n {% assign customer_qualifies = false %}\n{% elsif options.only_invite_if_the_customer_has_this_tag != blank %}\n {% assign customer_tags = order.customer.tags | downcase | split: \", \" %}\n {% assign tag_to_match = options.only_invite_if_the_customer_has_this_tag | strip | downcase %}\n {% unless customer_tags contains tag_to_match %}\n {% assign customer_qualifies = false %}\n {% endunless %}\n{% endif %}\n\n{% assign order_qualifies = false %}\n{% if customer_qualifies %}\n {% if options.only_invite_if_the_order_contains_a_product_with_this_tag == blank %}\n {% assign order_qualifies = true %}\n {% else %}\n {% for line_item in order.line_items %}\n {% assign product_tags = line_item.product.tags | split: \", \" %}\n {% if product_tags contains options.only_invite_if_the_order_contains_a_product_with_this_tag %}\n {% assign order_qualifies = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n {% endif %}\n{% endif %}\n\n{% if order.customer == nil %}\n {% log message: \"Order does not have a customer; skipping invitation\" %}\n{% elsif customer_qualifies == false %}\n {% log message: \"Customer does not qualify for an invitation\", customer_state: order.customer.state, customer_tags: order.customer.tags %}\n{% elsif order_qualifies == false and options.only_invite_if_the_order_contains_a_product_with_this_tag != blank %}\n {% log message: \"No qualifying product found\", required_product_tag: options.only_invite_if_the_order_contains_a_product_with_this_tag %}\n{% endif %} \n\n{% if order_qualifies %}\n {% assign customer_invite = hash %}\n\n {% if options.custom_invitation_email_subject != blank %}\n {% assign customer_invite[\"subject\"] = options.custom_invitation_email_subject %}\n {% endif %}\n\n {% if options.custom_invitation_email_message__multiline != blank %}\n {% assign customer_invite[\"custom_message\"] = options.custom_invitation_email_message__multiline %}\n {% endif %}\n\n {% if options.invitation_email_bcc__array != blank %}\n {% assign customer_invite[\"bcc\"] = options.invitation_email_bcc__array %}\n {% endif %}\n\n {% action \"shopify\" %}\n [\n \"post\",\n \"/admin/customers/{{ order.customer.id | json }}/send_invite.json\",\n {\n \"customer_invite\": {{ customer_invite | json }}\n }\n ]\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/orders/create"
],
"subscriptions_template": "shopify/orders/create",
"tags": [
"Email",
"Invite",
"Orders",
"Retention"
]
}