completeCartWorkflow and the heart of multi-vendor checkout. It groups the cart’s items by the seller behind each item’s offer, creates one order per seller (each carrying only that seller’s items, shipping methods, addresses, and promotion adjustments), and wraps them in a single OrderGroup the shopper tracks as one purchase. Along the way it validates seller items and shipping coverage, mirrors line-item ↔ offer links onto the new order items, reserves offer inventory, registers promotion usage, links orders to the cart, sellers, payment collection, and order group, authorizes the single payment session, distributes captured amounts proportionally as order transactions, and refreshes each order’s commission lines via refreshOrderCommissionLinesWorkflow. The run is idempotent per cart — an existing order group for the cart is returned instead of re-creating orders. Emits order.placed (one entry per child order) and order_group.created. Triggered by POST /store/carts/:id/complete.
Usage
Input
The cart to complete; must have an authorized-able payment session and seller-scoped shipping methods covering every seller in the cart.
Result
ID of the order group wrapping the per-seller orders — either newly created or the one already created for this cart.
Hooks
validate— runs after the cart is loaded (before any orders are created) with{ input, cart }.beforePaymentAuthorization— runs after orders and links are created, right before the payment session is authorized, with{ input }.orderGroupCreated— runs at the end of the creation branch with{ order_group_id, cart_id }.