completeCartWithSplitOrdersWorkflow. It takes a cart that may hold offers from
several sellers, creates one order per seller, and wraps them in an OrderGroup.
Run the workflow
src/api/store/carts/[id]/complete/route.ts
order_group_id instead of splitting again. It acquires a
lock on the cart id for the duration of the split so concurrent completions can’t
create duplicate orders.
Line items are grouped by
item.offer.seller_id. Sellers sell against the
shared master catalog through offers, so a line item’s seller comes from
its offer, never from product ownership.What happens during the split
For the cart, the workflow validates payments and per-seller shipping, then in a single transaction:- creates the parent
OrderGroup(customer_id,cart_id) - creates one child
Orderper seller from that seller’s items and shipping - links each order to the group, its seller, and the originating cart
- mirrors line-item → offer links, reserves offer inventory, and splits payment captures proportionally
- refreshes commission lines per order and marks the cart
completed_at
order.placed for the created orders and order_group.created
for the group.