Cart, Checkout, and Order Data Flow

TABLE OF CONTENTS


Solution Architecture Guidance

Separate Lifecycle Records

Treat cart, checkout and order as separate lifecycle records rather than one record that changes status. Each transition creates a new identifier, so requirements involving cross-stage reporting, integrations, troubleshooting or continuity must account for how data is copied and related across the stages.

Not every transaction goes through all three stages:

  • Approval-required orders go through an extra pending-approval record, with its own number, and only become an order once approved.
  • Quote-based orders go from cart to quote to order, without a checkout.

The platform does not store a link between the cart, checkout and order numbers. If cross-stage reporting or tracing is a requirement, that link needs to be captured explicitly as part of the solution.

Transaction Paths

Evaluate checkout changes across every applicable transaction path. Offline and zero-total orders, approval flows, online payments and quote-to-order conversion do not all follow the same route, even though they ultimately create an order. A customization implemented for only one path can produce inconsistent data or behavior in another.

Approval and online payment can also apply to the same order: the payment is authorized at checkout, captured when the order is approved, and voided if it is rejected.

Order as the Authoritative Record

Preserve the order as the authoritative record after placement. Requirements for receipts, order history, returns, payment reconciliation or downstream integrations should be based on order data, while abandoned or failed checkout investigation may depend on operational logs rather than an administrator-visible record. Two qualifications apply:

  • Before approval, the pending-approval record is the authoritative record, because no order exists yet.
  • For online payments, the payment is authorized before the order is created. Payment reconciliation should therefore use the payment gateway's transaction history alongside the order data. If an order fails after payment, the system voids or refunds the payment automatically, and that is recorded in the logs.

Project-Specific Checkout Data

Requirements that add project-specific data to checkout can affect more than the checkout experience, because that data may need to persist into the placed order and support downstream uses such as order history, reporting, approvals or integrations. The greater the number of transaction paths and downstream uses involved, the greater the implementation, testing and support scope.

Project-specific data is stored in a small number of shared custom-data slots, and two of them are already in use: one for checkout custom fields and approval manager details, and one for approver comments. Any new requirement must be designed so it doesn't overwrite existing data.

Overview

A cart, a checkout and an order are three separate records in Znode, each with its own number. This guide traces exactly what data moves between them, what shape it takes, and where to look when a value is wrong.

  • Product: Znode 10 storefront
  • For: implementation partners and developers
  • Companion to: the checkout workflow guide
  • Focus: data shapes, storage, debugging — not UI

Three records, three numbers. Nothing is renamed in place — each arrow mints a brand-new class number in a different collection.

Diagram of the three records in order: Carts (cartNumber, minted by Carts_addToCart), then copy-to-checkout to Checkout (checkoutNumber, minted by CommerceCollections_copy), then place-order to Orders (orderNumber, minted by CommerceCollections_placeOrder). A browser and session band above lists the CartNumber cookie, the encrypted _zn_tref sessionStorage entry and the UserOrderReceiptOrderId cookie.

CollectionNumberDescription
CartscartNumberCreated on first add-to-cart; lives in a cookie for guests.
CheckoutcheckoutNumberA copy of the cart; never a cookie, always encrypted in sessionStorage.
OrdersorderNumberThe permanent record once payment and placement succeed.

How the Three Numbers Relate

A trap worth knowing before you read any checkout code: several checkout and payment data shapes have a field literally called cartNumber that, once checkout has started, actually holds the checkout number. The storefront server always re-derives the real checkout number from the encrypted session header before using it — it never trusts the field name or the browser's value.

Diagram: the browser sends paymentRequest.cartNumber, which may be stale or absent; /api/payment-manager/create decrypts the x-checkout-ref header to the checkout number with getCheckoutNumberFromRequest(req); the server overwrites paymentRequest.cartNumber with checkoutNumber, calls createPayment, and getCartSummary(checkoutNumber) reads the authoritative total.

The field name survives across the type system (IPaymentRequest.cartNumber, createOrder's cartNumber argument), but by the time it reaches placeOrder it is the checkout class number — the value re-derived server side from x-checkout-ref, not whatever the browser sent.

TransitionTriggerCallNew number lands in
Cart createdFirst add-to-cartCarts_addToCartIAddToCartResponse.cartNumber
Cart → CheckoutShopper clicks CheckoutCommerceCollections_copy("Carts", cartNumber, "Checkout", origin)encrypted into sessionStorage["_zn_tref"]
Checkout → Orders (offline / zero total / approval)Place order submitCommerceCollections_placeOrder("Checkout", checkoutNumber, payload)IConvertedToOrderResponse.orderNumber
Checkout → Orders (online payment)Card / ACH / wallet submitCommerceCollections_generateFinalizeNumber reserves the number, then the same placeOrder callfinalClassNumber, then orderNumber
Quote → OrderApproved quote convertedplaceOrderFromQuote → CommerceCollections_placeOrder("quotes", ...)orderNumber, no checkout session involved

From Add-to-Cart to Order Confirmation

Solid arrows are requests, dashed arrows are responses. The browser never computes a total or sees the real checkout number in plain text — every amount shown on screen is re-read from the server on the next step.

Sequence diagram across Browser, /api/cart/*, /api/checkout/*, /api/payment-manager and Znode collections: 1 add-to-cart; 2 cartNumber and cartCount returned and stored in the CartNumber cookie; 3 POST copy-to-checkout; 4 encrypted checkoutRef returned and stored in sessionStorage _zn_tref; 5 address, shipping and discount updates sent with the x-checkout-ref header; 6 PUT finalize-number; 7 finalClassNumber returned; 8 POST payment-manager/create, which reads the server total, authorizes or captures, then places the order; 9 isSuccess and orderNumber returned and stored in the UserOrderReceiptOrderId cookie for /order/receipt.

Offline and zero-total orders skip steps 6–8 and call /api/place-order directly with the same effect: a validated placeOrder call against the checkout number.

Data Flow by Stage

Stage 1 - The Cart Stage

A cart holds line items and nothing about payment. Guests carry their cart number in a cookie; logged-in users have it looked up by user ID. When a guest logs in mid-shop, the two carts are merged into a third, new cart number — not either of the originals.

DataAgentShape
Line itemsgetCartItems(cartNumber)ICart — cartItems[] with sku, quantity, unitPrice, totalPrice, attributes, add-ons
Totals and discountsgetCartSummary(cartNumber, isCart, ...)ICartSummary — subTotal, total, shippingCost, taxCost, discounts[], costs[]
Guest → logged-in mergemergeGuestUserCartCarts_mergeCart → MergedCartNumber (a new cart number)

Note: getCartItems accepts a classType parameter and is reused later, unchanged, against "Checkout" and "Orders" — all three collections share the same item-list shape on the back end, which is why one function reads line items at every stage.

Stage 2 - Cart to Checkout: The Session Handoff

Checkout runs on a copy of the cart so the cart stays intact while the shopper pays, and each browser tab gets an independent session. The full extension-point discussion for this mechanism is in the checkout workflow guide; here is exactly what data moves.

STEP 1 - Copy the cart

POST /api/cart/copy-to-checkout reads cartNumber from the cookie and calls CommerceCollections_copy("Carts", cartNumber, "Checkout", origin). A new Checkout row is created with its own checkoutNumber; the cart row is untouched.

STEP 2 - Encrypt the reference

The route encrypts checkoutNumber with AES-GCM and returns { checkoutRef, serverNow }. This is the only form the checkout number ever takes outside the back end and a decrypted server request.

STEP 3 - Store it per tab

The browser saves checkoutRef in sessionStorage under _zn_tref — never a cookie, so one tab cannot see or clobber another tab's checkout.

STEP 4 - Attach it to every call

The shared httpRequest helper adds it as the x-checkout-ref header automatically on checkout calls. A route that forgets to call through httpRequest will never receive it.

STEP 5 - Decrypt and validate on the server

getCheckoutNumberFromRequest(request) decrypts the header (empty string if missing or tampered). validateCheckout(checkoutNumber) reports ACTIVE, INACTIVE, EXPIRED or NOT_FOUND — copying the cart again invalidates any earlier checkout for that cart.

Reliable: the checkout number is never readable in a URL, cookie, or page source — only a decrypted server request ever sees it in plain text.

Watch for: a direct visit to /checkout with no _zn_tref set sends the shopper back to the cart — this is expected, not a bug.

Stage 3 - The Checkout Stage: Where Each Piece Lands

Every write during checkout is keyed by the checkout number, not the cart number. Totals are re-read from the server on every step — the browser is never the source of truth for money.

DataWritten byZnode call
Shipping / billing addressupdateAddressIdsShippings_shippingAddress + Payments_payments, both keyed by checkoutNumber
Shipping methodupdateShippingDetailsShippings_orderShipment({ classNumber: checkoutNumber, shippingId, ... })
Discounts / vouchersapplyDiscount (isCheckout: true)recalculated through the same getCartSummary path as the cart page
Totals shown on review— (read-only)getCartSummary(checkoutNumber, false, ...)
Custom checkout data (project-specific fields, approval routing, vouchers)placeOrder, before the order is placedOrder_updateOrderDetails({ endpoint: "carts", orderPayload: { classNumber: checkoutNumber, customData: { custom1: JSON.stringify(data) } } })

Important: custom checkout data is a JSON string inside customData.custom1 (or custom2–custom5), not a separate column. Each write replaces that slot entirely — two features writing the same slot will overwrite each other. If a custom value "isn't showing up," check for a second write clobbering it or a stringify/parse mismatch before assuming the feature itself is broken.

Two Submit Paths, One Choke Point

PathPayload typeRouteConverges on
Offline payment, zero total, approvalIConvertToOrderPOST /api/place-order, /api/submit-for-approvalplaceOrder(convertToOrderRequestModel, checkoutNumber)
Online payment (card, ACH, wallets, APM)IPaymentRequestPUT /api/place-order/finalize-number then POST /api/payment-manager/create

Both payloads carry the same underlying data in two different shapes. placeOrder in the checkout agent is the single point every path passes through before CommerceCollections_placeOrder runs — it is also where the server-side total check lives:

packages/agents/src/checkout/checkout.ts (placeOrder)
if (!paymentDetails.configurationSetCode) {
  const cartSummary = await getCartSummary(checkoutNumber);     // checkoutNumber, read from the server
  if (cartSummary?.orderTotalWithoutVoucher > 0) {
    return { isSuccess: false };                                // refuse a "free" order that isn't actually free
  }
}

Stage 4 - Checkout to Order, and Reading It Back

CommerceCollections_placeOrder("Checkout", checkoutNumber, payload) returns the order number and the payment outcome in one response. From here on, the order number is the only key that matters — receipts, order history, returns and payment capture all key off it, never the checkout number.

Field on the order rowWhat it holds
Total, SubTotalDirect columns
CostFactorResponse[]An array of { Name, Value } pairs — TaxCost, ShippingCost, HandlingFee, CSRDiscount, TotalDiscount, ImportDuty are all read out of here by name
LineItemDetailsLine items, mapped the same way as cart line items
PaymentDetailspaymentSubTypeCode, configurationSetCode, RemainingOrderAmount for partial/invoice payments
CustomData.custom1 / custom2JSON-stringified project-specific checkout data, carried over from the checkout row

Payment gateway transaction history (authorize / capture / void events) is a separate call, Payments_paymentTransactionHistoryByClassNumber(orderNumber) — it is not part of the order row itself.

Data Storage Across Stages

DataBrowser / sessionCartCheckoutOrder
IdentifierCartNumber cookiecartNumbercheckoutNumber, encrypted in sessionStorage onlyorderNumber, briefly in a cookie for the receipt
Line itemsrender state onlyICartItem[]same shape, keyed by checkoutNumberLineItemDetails
Shipping addressin-memory until submitguest snapshot in localStorage onlyShippings_shippingAddress rowIAddress flagged isShipping
Billing addresssame—Payments_payments rowIAddress flagged isBilling
Payment methodcomponent state until submit—resolved at submit, not stored mid-checkoutPaymentDetails.configurationSetCode
Totals / discountsnever computed client-sideICartSummaryICartSummary, same shapeTotal, SubTotal, CostFactorResponse[]
Custom checkout dataform state—CustomData.custom1/custom2 (JSON)same slot, carried over

Example: Wrong Order Total

STEP 1 - Get the order number

From the receipt email, or Znode Admin → Orders if you only have a date or email address.

STEP 2 - Pull the order row

In Admin, or via getOrder(orderNumber) in code — both read CommerceCollections_classDetailsByClassType("Orders", orderNumber).

STEP 3 - Read the cost breakdown, not just the total

Check each entry in CostFactorResponse (TaxCost, ShippingCost, HandlingFee, CSRDiscount, TotalDiscount, ImportDuty) against what the customer expected. A wrong total is almost always one factor, not the subtotal.

STEP 4 - Check custom data for pricing inputs

If the store has a project-specific pricing rule (a voucher, an approval discount, a negotiated rate), parse CustomData.custom1/custom2 — this often shows whether the rule fired with the wrong input, versus not firing at all.

STEP 5 - Compare against the actual payment

Payments_paymentTransactionHistoryByClassNumber(orderNumber) shows what the gateway actually authorized and captured. A mismatch against Total here points at a gateway-side rounding or currency issue, not storefront logic — the storefront always reads totals server-side before charging.

STEP 6 - If it looks pre-order, check the logs

The checkout row itself may already be superseded once an order exists. Server logs under Webstore_Checkout and Webstore_Cart around the order's timestamp show the cart/checkout summary calls and discount applications, including which checkout number was involved.

STEP 7 - Last resort: a custom rule

Search the project's own checkout customization folder for anything that recalculates or overrides a cost factor outside getCartSummary.

Log areaCovers
Webstore_CartAdd to cart, cart summary, merge, item mutations
Webstore_CheckoutCheckout session, address/shipping updates, placeOrder, validateCheckout
Webstore_PaymentcreatePayment, gateway calls, payment-manager routes
Webstore_OrderOrder placement result handling, refund/void on failure

Admin shows the placed order's line items, addresses, payment status, cost factors and custom data — the same row the storefront reads.

Admin does not show an abandoned checkout's sessionStorage state or the encrypted checkout reference. For those, use server logs filtered by area, and the browser's own storage/network tab if you can reproduce it.

Golden Rules

RuleDetails
Three numbers, not onecartNumber, checkoutNumber and orderNumber are different values in different collections, minted fresh at each transition.
cartNumber can lieOn checkout and payment types, a field called cartNumber may actually carry the checkout number — the server always re-derives the real one.
Money is never client-sideEvery total used to place an order or charge a payment is re-read from getCartSummary on the server.
Custom data lives in one JSON slotcustomData.custom1–5 hold stringified project data; each write replaces the whole slot.
The checkout number never leaves the server in plain textOnly sessionStorage (encrypted) and a decrypted server request ever hold it.
Once an order exists, it is the recordThe checkout row that produced it may already be superseded — debug from the order outward, not the checkout.

Troubleshooting

You seeWhat it usually means
Order total doesn't match what the cart showedCheck CostFactorResponse on the order, not just Total — a discount, tax or shipping factor differs from the cart-page estimate
Custom checkout field missing from the orderAnother write replaced the customData slot, or the field was added to only one of the two submit paths (offline vs. online payment)
Checkout session keeps expiringNo _zn_tref in sessionStorage (direct visit), another tab replaced it, or the timer setting is too short
"cartNumber" in a checkout log line looks like a checkout numberIt is — that field is overloaded after checkout starts; confirm against the encrypted header, not the field name
Payment succeeded but no order appearedCheck Webstore_Order logs for a refund/void — placeOrder releases a successful payment automatically when the order itself fails to place
Guest's cart items vanished after loginExpected if the login-time merge produced a different MergedCartNumber than either input cart


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.