This documentation provides a reference to the fetchShippingOptionForOrderWorkflow
. It belongs to the @medusajs/medusa/core-flows
package.
This workflow fetches a shipping option for an order. It's used in Return Merchandise Authorization (RMA) flows. It's used by other workflows, such as createClaimShippingMethodWorkflow.
You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around fetching shipping options for an order.
Source CodeWorkflow hook
Step conditioned by when
View step details
AdditionalData & object
AdditionalData & objectAdditionalData
objectadditional_data
property accepted in HTTP
requests, that allows passing custom data and handle them in hooks.
Learn more in this documentation.shipping_option_id
stringcurrency_code
stringorder_id
stringcontext
CalculatedRMAShippingContextShippingOptionDTO & object
ShippingOptionDTO & objectShippingOptionDTO
objectcalculated_price
objectHooks allow you to inject custom functionalities into the workflow. You'll receive data from the workflow, as well as additional data sent through an HTTP request.
Learn more about Hooks and Additional Data.
This hook is executed before the shipping option is fetched. You can consume this hook to set the pricing context for the shipping option. This is useful when you have custom pricing rules that depend on the context of the order.
For example, assuming you have the following custom pricing rule:
You can consume the setPricingContext
hook to add the location_id
context to the prices calculation:
1import { fetchShippingOptionForOrderWorkflow } from "@medusajs/medusa/core-flows";2import { StepResponse } from "@medusajs/workflows-sdk";3 4fetchShippingOptionForOrderWorkflow.hooks.setPricingContext((5 { shipping_option_id, currency_code, order_id, context, additional_data }, { container }6) => {7 return new StepResponse({8 location_id: "sloc_123", // Special price for in-store purchases9 });10});
The shipping option's price will now be retrieved using the context you return.
Handlers consuming this hook accept the following input.
input
AdditionalData & objectshipping_option_id
stringcurrency_code
stringorder_id
stringcontext
CalculatedRMAShippingContextadditional_data
Record<string, unknown>Optionaladditional_data
property in HTTP requests.
Learn more in this documentation.