Skip to main content
Seller-aware variant of Medusa’s addShippingMethodToCartWorkflow. Validates the requested options against the cart and their calculated prices, then swaps shipping methods per seller: existing methods belonging to the sellers whose options are being added are removed, while other sellers’ methods stay untouched — so a multi-seller cart keeps one shipping method per seller. Refreshes cart items afterwards and emits cart.updated. Triggered by POST /store/carts/:id/shipping-methods.

Usage

import { addSellerShippingMethodToCartWorkflow } from "@mercurjs/core/workflows"

await addSellerShippingMethodToCartWorkflow(container).run({
  input: {
    cart_id: "cart_123",
    options: [{ id: "so_123" }],
  },
})

Input

cart_id
string
required
The cart to add shipping methods to.
options
object[]
required
Shipping options to add as methods.
additional_data
object
Custom data passed through to the workflow hooks.

Result

result
void
No return value; the cart’s shipping methods are replaced per seller as a side effect.

Hooks

  • validate — runs after the cart is loaded with { input, cart }.
addSellerShippingMethodToCartWorkflow.hooks.validate(async ({ input, cart }) => {
  // throw to reject the shipping method
})