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

# Order splitting

> How a multi-seller cart becomes a group of independent per-seller orders.

This page covers how a single cart spanning multiple sellers is split into
per-seller orders at checkout.

## Why carts are split

A marketplace cart can hold offers from many different sellers. Each seller
fulfills, ships, and settles independently, so a single combined order would be
impossible to operate. Instead, on completion the cart is divided along seller
boundaries. Every seller with items in the cart gets its own `Order`, and all of
those orders are attached to one parent `OrderGroup`.

The split is driven by the `completeCartWithSplitOrdersWorkflow`. It groups the
cart's line items by the seller behind each offer, and builds one order per
seller from that seller's items and shipping methods.

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

const { result } = await completeCartWithSplitOrdersWorkflow(container).run({
  input: { cart_id: "cart_123" },
})
// result.order_group_id -> the parent group
```

<Note>
  Items are grouped by `item.offer.seller_id`. Sellers list against the shared
  master catalog through **offers**, so the offer, not the product, is what
  ties a line item to a seller.
</Note>

## What the split produces

For each seller in the cart the workflow, in one transaction:

* creates a child `Order` with that seller's line items and shipping methods
* links each order to the group (`order_group_order`) and to its seller (`order_order_seller_seller`)
* mirrors the line-item → offer links onto the new order lines
* splits payment captures proportionally across the child orders
* reserves offer-scoped inventory and refreshes commission lines per order

Once every child order is created, the workflow emits `order.placed` for the
orders and `order_group.created` for the group.

<Tip>
  Promotions are attributed per seller: a seller-scoped promotion links only to
  that seller's child order, while marketplace-wide promotions are applied as
  cart adjustments and belong to no single order.
</Tip>

## Independent child orders

After the split, each child order lives its own life. Fulfillment, returns, and
refunds are handled per order, so one seller can ship while another is still
preparing, without affecting the rest of the group. The group remains the
single reference the shopper uses to see the purchase as a whole.
