[ { "version": 1, "label": "Tag customers who purchase more than X products from a set of collections", "trigger_type": [ "order_created" ], "object_type": "order", "app_id": "triggers", "settings": { "priority": 0, "condition_groups": { "1": { "conditions": { "1": { "field": "order.line_items.product.collections", "settings": { "multiple": "any", "operator": "equals_one", "value": "", "long_value": "{% for item in workflow_vars[\"collections\"].value|split(',') %}\r\n{{item|trim}}\r\n{% endfor %}", "token_object_type": "order", "condition_type": "AND" }, "weight": 999 }, "2": { "field": "order.customer.tags_array", "settings": { "multiple": "none", "operator": "equals", "value": "{{ workflow_vars[\"tag\"].value }}", "long_value": "", "token_object_type": "order", "condition_type": "AND" }, "weight": 999 } }, "actions": { "1": { "type": "shopify_api_request", "settings": { "token_object_type": "order", "label": "Get all orders from a customer", "method": "GET", "path": "orders.json?customer_id={{ order.customer.id }}&limit=250&status=any&fields=id,name", "data": "", "response_handle": "response_twig", "response_object_type": "", "parent_data": "", "workflow_actions": [], "twig": "{% set found = 0 %}\r\n{% for ord in response.orders %}\r\n{% set f_order= load('order',ord[\"id\"]) %}\r\n{% for line_item in f_order.line_items if found < workflow_vars[\"products_count_limit\"].value %}\r\n {% for collection in line_item.product.collections if workflow_vars[\"collections\"].value|split(',')|contains(collection) %}\r\n {% set found = found|plus(line_item.quantity) %} \r\n {% endfor %}\r\n{% endfor %}\r\n{% endfor %}\r\n\r\n{% if workflow_vars[\"products_count_limit\"].value <= found %}\r\n\r\n {% do QUEUE_ACTION(\"customer_add_tags\", {\r\n resource: order.customer,\r\n tags: [workflow_vars[\"tag\"].value ]\r\n }) %}\r\n\r\n{% endif %}", "wait": "0", "cw_timezone": "America\/New_York", "custom_wait": "", "run_once": 0 }, "weight": 999, "target_key": "order" } } } } }, "description": "This automation is triggered when an order is raised. It checks the purchased items to see if the number of items from the predefined collection exceeds the set limit and then tags the customer.", "variables": { "tag": { "label": "Tag", "machine_name": "tag", "type": "triggers_text", "settings": { "can_be_disabled": true, "disabled": false, "attributes": { "width": null, "bulk_ops_editable": 1, "input_instructions": "", "description": "", "default_value": "locked" }, "weight": 1, "validations": [], "conditions": [] } }, "products_count_limit": { "label": "Products count limit", "machine_name": "products_count_limit", "type": "triggers_text", "settings": { "can_be_disabled": true, "disabled": false, "attributes": { "width": null, "bulk_ops_editable": 1, "input_instructions": "", "description": "", "default_value": "2" }, "weight": 2, "validations": [], "conditions": [] } }, "collections": { "label": "Collections", "machine_name": "collections", "type": "triggers_text", "settings": { "can_be_disabled": true, "disabled": false, "attributes": { "width": null, "bulk_ops_editable": 1, "input_instructions": "Add a comma separated list of collections to check from", "description": "", "default_value": "IWIA" }, "weight": 7, "validations": [], "conditions": [] } } } } ]