{
  "name": "Roll two stores into one order sheet",
  "nodes": [
    {
      "parameters": {
        "content": "## Roll two stores into one order sheet\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "64dda8f7-fba4-4947-b6b3-df6a717de43c",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "c96e0956-d165-4dc9-8327-791f20c9c32d",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "multi-store-order-rollup",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "45bd4c5f-fa78-4bce-8ad3-3a400a1e76ca",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "4adef0ea-c461-4522-976d-a7ec4c5dca65"
    },
    {
      "parameters": {
        "topic": "orders/create"
      },
      "id": "6eb9621c-bd5b-40c1-b26e-e05e183e23a5",
      "name": "Shopify order trigger",
      "type": "n8n-nodes-base.shopifyTrigger",
      "typeVersion": 1,
      "position": [
        40,
        640
      ],
      "credentials": {
        "shopifyAccessTokenApi": {
          "id": "PLACEHOLDER_SHOPIFYACCESSTOKENAPI",
          "name": "Shopify access token"
        }
      },
      "notes": "Fires on orders/create after the Shopify credential is connected.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"orderId\": \"1044\",\n  \"email\": \"buyer@example.com\",\n  \"total\": 320,\n  \"currency\": \"USD\",\n  \"country\": \"US\",\n  \"financialStatus\": \"paid\",\n  \"itemCount\": 2,\n  \"shippingMethod\": \"standard\"\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "66cfc10c-8236-4d6f-8ecb-ab3f8daf5afc",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst total = Number(item.total || item.amount || 0);\nconst country = String(item.country || item.shippingCountry || 'US');\nconst financial = String(item.financialStatus || item.status || 'paid').toLowerCase();\nconst tags = [];\nlet route = 'fulfill';\nif (financial === 'refunded' || financial === 'voided') route = 'refund';\nelse if (financial === 'pending' || financial === 'cod') route = 'verify-payment';\nelse if (total >= 250) route = 'vip';\nelse if (['BR', 'IN', 'NG'].includes(country) && item.shippingMethod === 'express') route = 'fraud-review';\nif (Number(item.itemCount || 1) >= 8) tags.push('bulk');\nif (route === 'vip') tags.push('vip');\nconst record = {\n  orderId: item.orderId || item.id,\n  store: 'Shopify',\n  email: item.email || '',\n  total,\n  currency: item.currency || 'USD',\n  country,\n  financialStatus: financial,\n  route,\n  tags: tags.join(','),\n  title: 'Shopify' + ' ' + (item.orderId || ''),\n};\nreturn {\n  summary: 'Shopify' + ' order ' + record.orderId + ' routed to ' + route + ' (' + total + ' ' + record.currency + ').',\n  route,\n  record,\n  slackText: route.toUpperCase() + ' ' + record.orderId + ' for ' + (item.email || 'guest') + ' \u2014 ' + total,\n  actions: [{ app: 'Shopify', operation: route, payload: record }],\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "344861d8-d214-4ab5-92ae-b07f204a1e3d",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "47a1cc16-d36d-4ac1-a136-d5d410d544ad",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8230db45-4365-4b1b-a827-efda37814cab",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'multi-store-order-rollup',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "f58aad0e-596e-4d8e-98d0-abeca7a7b19b",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "All orders"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "b78a4320-7e81-4faf-ad17-09b64162bbdb",
      "name": "Append All orders",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "PLACEHOLDER_GOOGLESHEETSOAUTH2API",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#daily-orders"
        },
        "text": "={{ $json.slackText || $json.summary }}",
        "otherOptions": {}
      },
      "id": "04f5bd89-fa8f-42ec-b23e-d1487020dfbb",
      "name": "Post #daily-orders",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "slackOAuth2Api": {
          "id": "PLACEHOLDER_SLACKOAUTH2API",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "79ec0f7b-11f2-4638-b9e0-6dfff3b62896",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shopify order trigger": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append All orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append All orders": {
      "main": [
        [
          {
            "node": "Post #daily-orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Shopify and WooCommerce orders share one route and one sheet, with the store name on every row, so a daily Slack total is possible."
  },
  "active": false
}
