> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mercurjs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# completeCartWithSplitOrdersWorkflow

> Complete a multi-seller cart by splitting it into per-seller orders under an order group.

Mercur's replacement for Medusa's `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

```ts theme={null}
import { completeCartWithSplitOrdersWorkflow } from "@mercurjs/core/workflows"

const { result } = await completeCartWithSplitOrdersWorkflow(container).run({
  input: { cart_id: "cart_123" },
})
```

## Input

<ParamField body="cart_id" type="string" required>The cart to complete; must have an authorized-able payment session and seller-scoped shipping methods covering every seller in the cart.</ParamField>

## Result

<ResponseField name="result.order_group_id" type="string">ID of the order group wrapping the per-seller orders — either newly created or the one already created for this cart.</ResponseField>

## 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 }`.

```ts theme={null}
completeCartWithSplitOrdersWorkflow.hooks.validate(async ({ input, cart }) => {
  // throw to block checkout
})
```
