Workflows
addSellerShippingMethodToCartWorkflow
This documentation provides a reference to theaddSellerShippingMethodToCartWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow adds a shipping method to a cart, ensuring it’s linked to the correct seller. It handles replacing existing shipping methods for the same seller and validating the new option.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/carts/[id]/shipping-methods/route.ts
Steps
- validateCartShippingOptionsStep: Validates that the shipping option is valid for the cart and compatible with other options.
- addShippingMethodToCartWorkflow: Adds the shipping method to the cart using Medusa’s core workflow.
- useQueryGraphStep: Fetches seller shipping options to correctly map the new method to a seller and handle replacements.
- addShippingMethodToCartStep: Finalizes the addition of the shipping method, ensuring it replaces any existing method for the same seller.
Input
deleteSellerLineItemWorkflow
This documentation provides a reference to thedeleteSellerLineItemWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow deletes a line item from a cart and also removes any associated shipping method for that seller if it’s no longer valid (e.g. if the cart no longer has items from that seller).
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/carts/[id]/line-items/[line_id]/route.ts
Steps
- useQueryGraphStep: Fetches the line item and cart details to determine the seller and associated shipping options.
- removeShippingMethodFromCartStep: Removes the shipping method if the item being deleted was the last one for that seller.
- deleteLineItemsWorkflow: Deletes the line item from the cart.
Input
listSellerReturnShippingOptionsForOrderWorkflow
This documentation provides a reference to thelistSellerReturnShippingOptionsForOrderWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow retrieves available return shipping options for a specific order, filtering them based on the seller associated with the order.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/shipping-options/return/route.ts
Steps
- useQueryGraphStep: Fetches the order to identify the cart and seller shipping options.
- listShippingOptionsForCartWorkflow: Retrieves available shipping options for the cart using Medusa’s core workflow.
Input
Output
The list of available return shipping options.
listSellerShippingOptionsForCartWorkflow
This documentation provides a reference to thelistSellerShippingOptionsForCartWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow lists valid shipping options for a cart, ensuring that only options relevant to the sellers present in the cart are returned. It filters out options for sellers that already have a shipping method selected, unless it’s for a replacement.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/shipping-options/route.ts
Steps
- listShippingOptionsForCartWorkflow: Lists all potential shipping options for the cart.
- filterSellerShippingOptionsStep: Filters the options to ensure they match the sellers of the items in the cart and handles logic for existing selections.
Input
Output
The filtered list of shipping options.
removeCartShippingMethodsWorkflow
This documentation provides a reference to theremoveCartShippingMethodsWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow removes specified shipping methods from a cart.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/carts/[id]/shipping-methods/route.ts
Steps
- removeShippingMethodFromCartStep: Removes the shipping methods from the cart.
Input
splitAndCompleteCartWorkflow
This documentation provides a reference to thesplitAndCompleteCartWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow completes a cart by splitting it into multiple orders based on the sellers of the items. It handles payment authorization, inventory reservation, and creating the OrderSet which groups the individual seller orders.
Source code
Examples
- API Route
packages/modules/b2c-core/src/api/store/carts/[id]/complete/route.ts
Steps
- useRemoteQueryStep: Fetches the cart and checks for an existing OrderSet.
- validateCartSellersStep: Validates the sellers associated with the cart items.
- validateCartShippingOptionsStep: Validates the shipping options for each seller.
- validateCartPaymentsStep: Validates the payment sessions.
- authorizePaymentSessionStep: Authorizes the payment.
- registerUsageStep: Registers promotion usage.
- createOrderSetStep: Creates the OrderSet entity.
- createOrdersStep: Creates individual orders for each seller.
- createSplitOrderPaymentsStep: Creates payment records for each split order.
- createRemoteLinkStep: Links orders to sellers, the OrderSet, and payment collections.
- reserveInventoryStep: Reserves inventory for the items.
- updateCartsStep: Updates the cart status to completed.
- emitEventStep: Emits
order.placedandorder-set.placedevents.
Input
Output
The created OrderSet.
Steps
createOrderSetStep
Creates anOrderSet record which groups multiple orders created from a single cart.
Source code
Input
The data to create the OrderSet.
Output
The created OrderSet.
filterSellerShippingOptionsStep
Filters a list of shipping options to only include those relevant for the sellers currently in the cart that still need a shipping method selected. Source codeInput
Output
The filtered list of shipping options.
validateCartSellersStep
Validates that all items in the cart are associated with valid sellers. Source codeInput
Output
Throws an error if validation fails.