fetchShippingOptionForOrderWorkflow - Medusa Core Workflows Reference
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 CodeExamples#
Steps#
Workflow hook
Step conditioned by when
View step details
Input#
AdditionalData & object
AdditionalData & object
AdditionalData & object
AdditionalData & objectAdditionalData
AdditionalData
AdditionalData
AdditionalDatashipping_option_id
stringThe ID of the shipping option to fetch.
shipping_option_id
stringcurrency_code
stringThe currency code of the order.
currency_code
stringorder_id
stringThe ID of the order.
order_id
stringcontext
CalculatedRMAShippingContextThe context of the RMA flow, which can be useful for retrieving the shipping option's price.
context
CalculatedRMAShippingContextThe custom amount of the shipping option.
If not provided, the shipping option's amount is used.
Output#
ShippingOptionDTO & object
ShippingOptionDTO & object
ShippingOptionDTO & object
ShippingOptionDTO & objectShippingOptionDTO
ShippingOptionDTOThe shipping option details.
ShippingOptionDTO
ShippingOptionDTOcalculated_price
objectThe shipping option's price.
calculated_price
objectHooks#
Hooks 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.
setPricingContext#
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.
Example
Input
Handlers consuming this hook accept the following input.
input
AdditionalData & object
input
AdditionalData & objectshipping_option_id
stringThe ID of the shipping option to fetch.
shipping_option_id
stringcurrency_code
stringThe currency code of the order.
currency_code
stringorder_id
stringThe ID of the order.
order_id
stringcontext
CalculatedRMAShippingContextThe context of the RMA flow, which can be useful for retrieving the shipping option's price.
context
CalculatedRMAShippingContextadditional_data
Record<string, unknown>OptionalAdditional data that can be passed through the additional_data
property in HTTP requests.
Learn more in this documentation.
additional_data
Record<string, unknown>Optionaladditional_data
property in HTTP requests.
Learn more in this documentation.