-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathauto-untag-customers-when-a-certain-product-is-refunded.json
22 lines (22 loc) · 2.48 KB
/
auto-untag-customers-when-a-certain-product-is-refunded.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "Use this task to automatically remove a certain customer tag whenever a particular product is refunded, for that customer.\n\nThis task is configured with one or more product IDs ([learn how to find a product ID](https://help.usemechanic.com/en/articles/2946120-how-do-i-find-an-id-for-a-product-collection-order-or-something-else)), and with the customer tag to remove when one of those products is refunded.",
"halt_action_run_sequence_on_error": false,
"name": "Auto-untag customers when a certain product is refunded",
"online_store_javascript": null,
"options": {
"product_ids__number_array_required": null,
"customer_tag_to_remove__required": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% if event.preview %}\n {% assign refund = hash %}\n {% assign refund[\"refund_line_items\"] = array %}\n {% assign refund[\"refund_line_items\"][0] = hash %}\n {% assign refund[\"refund_line_items\"][0][\"line_item\"] = hash %}\n {% assign refund[\"refund_line_items\"][0][\"line_item\"][\"product_id\"] = options.product_ids__number_array_required.first %}\n {% assign refund[\"order\"] = hash %}\n {% assign refund[\"order\"][\"customer\"] = hash %}\n {% assign refund[\"order\"][\"customer\"][\"admin_graphql_api_id\"] = \"gid://shopify/Customer/1234567890\" %}\n {% assign refund[\"order\"][\"customer\"][\"tags\"] = options.customer_tag_to_remove__required %}\n{% endif %}\n\n{% assign refunded_product_ids = refund.refund_line_items | map: \"line_item\" | map: \"product_id\" %}\n\n{% assign refund_qualifies = false %}\n\n{% for product_id in options.product_ids__number_array_required %}\n {% if refunded_product_ids contains product_id %}\n {% assign refund_qualifies = true %}\n {% break %}\n {% endif %}\n{% endfor %}\n\n{% assign customer = refund.order.customer %}\n{% assign customer_tags = refund.order.customer.tags | split: \",\" %}\n\n{% if refund_qualifies and customer_tags contains options.customer_tag_to_remove__required %}\n {% action \"shopify\" %}\n mutation {\n tagsRemove(\n id: {{ customer.admin_graphql_api_id | json }}\n tags: {{ options.customer_tag_to_remove__required | json }}\n ) {\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endif %}",
"subscriptions": [
"shopify/refunds/create"
],
"subscriptions_template": "shopify/refunds/create",
"tags": [
"Customers",
"Refunds",
"Untag"
]
}