completeCartWithSplitOrdersWorkflow, which creates one order per seller and wraps them in an order group. Understanding the split tells you where each seller’s items, shipping, promotions, and payment end up.
Items follow the offer’s seller
The workflow groups line items byitem.offer.seller_id. Sellers sell against a shared master catalog through offers, so the offer, not the product, ties a line item to a seller. Every seller with at least one item gets one child order.
The split enforces two rules before it creates anything:
- Every item has a seller:
validateSellerCartItemsStepthrowsINVALID_DATAwhen any line item has no offer with aseller_id - Every seller’s shipping is covered:
validateSellerCartShippingStepthrows when items that require shipping have no matching shipping method
Promotions stay with their seller
Promotion adjustments are split by scope. A promotion linked to a seller only keeps its adjustments on that seller’s items and shipping, and the workflow links the promotion to that seller’s child order. A marketplace promotion with no seller keeps its adjustments on every order it touched, and the workflow links it to no order.What the split creates
The workflow creates everything for the group in one run:- Create the
OrderGroupwith the cart’scustomer_idandcart_id. - Create one
Orderper seller, with statuspendingunless thesetOrderStatushook says otherwise. - Link each order to the group, its seller, and the cart, and link new customers to the sellers they bought from.
- Mirror each cart line item’s offer link onto the new order line item.
- Reserve inventory for offers that manage inventory, and register promotion usage.
- Set
completed_aton the cart and emitorder.placedandorder_group.created. - Authorize the payment session, split a captured payment, and refresh commission lines per order.
{ order_group_id }. Mercur’s cart completion route and its processPaymentWorkflow both run this workflow, so a webhook-driven checkout also produces a group.
Payment stays on the cart until capture
The child orders share the cart’s payment collection until the payment is captured. Medusa allows a payment collection to belong to one order only, so the split doesn’t link the orders to it. Once the payment is captured,splitCapturedCartPaymentWorkflow gives each order a payment collection of its own for its share. It runs inside checkout for providers that capture on authorization, and from the payment.captured subscriber for the rest.
One group per cart
The split runs at most once per cart. The workflow takes a lock on the cart id, then looks for an existing group with the samecart_id. If it finds one, it skips the split and returns that group’s id, so a retried request or a duplicate webhook can’t create a second set of orders.