Created
October 25, 2024 02:22
-
-
Save stevenhoney/9dabcd3675dcac41b31642d2e7a0aed0 to your computer and use it in GitHub Desktop.
Shopify Flow Template - demonstrates sending an internal email when an order contains 'adjacent' variants of the same product, e.g. Large and XL of the same apparel product.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a042788e508239644175e7d0ad51b8fcfc9da71f506e9c40401cd0f3d2fe68ac:{"__metadata":{"version":0.1},"root":{"steps":[{"step_id":"b2a99540-9272-11ef-92ca-3fbe2773e2e8","step_position":[900,1100],"config_field_values":[],"task_id":"shopify::admin::order_created","task_version":"0.1","task_type":"TRIGGER","description":null,"note":null,"name":null},{"step_id":"ff8d44b0-9272-11ef-92ca-3fbe2773e2e8","step_position":[1220,1280],"config_field_values":[{"config_field_id":"input","value":"query{\n order {\n lineItems {\n product {\n handle\n }\n variant {\n position\n }\n }\n }\n}"},{"config_field_id":"script","value":"export default function main(input) {\n // Function to check adjacent variant positions\n let hasAdjacentVariants = false;\n // Group line items by product handle\n const groupedItems = input.order.lineItems.reduce((acc, item) => {\n const handle = item.product.handle;\n if (!acc[handle]) {\n acc[handle] = [];\n }\n acc[handle].push(item.variant.position);\n return acc;\n }, {});\n \n // Check for adjacent variants in each product group\n Object.keys(groupedItems).forEach(handle => {\n const positions = groupedItems[handle];\n console.log(positions);\n // Sort positions to check adjacency\n positions.sort((a, b) => a - b);\n \n for (let i = 0; i < positions.length - 1; i++) {\n const current = positions[i];\n const next = positions[i + 1];\n \n // Check if adjacent\n if (next === current + 1 || next === current - 1) {\n hasAdjacentVariants = true;\n break; // No need to check further for this handle\n }\n }\n });\n // Return the result\n return {\n message: hasAdjacentVariants\n }\n}"},{"config_field_id":"output_schema","value":"\"The output of Run Code\"\ntype Output {\n \"The message returned by the script\"\n message: Boolean!\n}"}],"task_id":"shopify::flow::run_code","task_version":"0.1","task_type":"ACTION","description":null,"note":null,"name":"Run code"},{"step_id":"185e1570-9276-11ef-9bd1-e917ae3f2d42","step_position":[1560,1460],"config_field_values":[{"config_field_id":"condition","value":"{\"uuid\":\"1da3e050-9276-11ef-9bd1-e917ae3f2d42\",\"lhs\":{\"uuid\":\"1b7cba90-9276-11ef-9bd1-e917ae3f2d42\",\"parent_uuid\":\"1da3e050-9276-11ef-9bd1-e917ae3f2d42\",\"lhs\":{\"uuid\":\"1da3b940-9276-11ef-9bd1-e917ae3f2d42\",\"parent_uuid\":\"1b7cba90-9276-11ef-9bd1-e917ae3f2d42\",\"value\":\"runCode.message\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"runCode.message\"},\"rhs\":{\"uuid\":\"1e507400-9276-11ef-9bd1-e917ae3f2d42\",\"parent_uuid\":\"1b7cba90-9276-11ef-9bd1-e917ae3f2d42\",\"value\":\"true\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:Boolean\",\"operator\":\"==\",\"operation_type\":\"Comparison\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"}"}],"task_id":"shopify::flow::condition","task_version":"0.1","task_type":"CONDITION","description":null,"note":null,"name":null},{"step_id":"38de1750-9276-11ef-9bd1-e917ae3f2d42","step_position":[1880,1640],"config_field_values":[{"config_field_id":"address","value":"[email protected]"},{"config_field_id":"subject","value":"Adjacent SKUs Ordered"},{"config_field_id":"message","value":"Contact this customer"}],"task_id":"shopify::flow::send_email","task_version":"0.1","task_type":"ACTION","description":null,"note":null,"name":null}],"links":[{"from_step_id":"b2a99540-9272-11ef-92ca-3fbe2773e2e8","from_port_id":"output","to_step_id":"ff8d44b0-9272-11ef-92ca-3fbe2773e2e8","to_port_id":"input"},{"from_step_id":"ff8d44b0-9272-11ef-92ca-3fbe2773e2e8","from_port_id":"output","to_step_id":"185e1570-9276-11ef-9bd1-e917ae3f2d42","to_port_id":"input"},{"from_step_id":"185e1570-9276-11ef-9bd1-e917ae3f2d42","from_port_id":"true","to_step_id":"38de1750-9276-11ef-9bd1-e917ae3f2d42","to_port_id":"input"}],"patched_fields":[],"workflow_name":"Flag Adjacent Variants"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment