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 Code

Examples#

Steps#

Input#

AdditionalData & objectAdditionalData & object
AdditionalDataAdditionalData
shipping_option_idstring
The ID of the shipping option to fetch.
currency_codestring
The currency code of the order.
order_idstring
The ID of the order.
contextCalculatedRMAShippingContext
The context of the RMA flow, which can be useful for retrieving the shipping option's price.
custom_amountnull | BigNumberInputOptional
The custom amount of the shipping option. If not provided, the shipping option's amount is used.

Output#

ShippingOptionDTO & objectShippingOptionDTO & object
ShippingOptionDTOShippingOptionDTO
The shipping option details.
calculated_priceobject
The shipping option's price.

Hooks#

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:

Code
1{2  "attribute": "location_id",3  "operator": "eq",4  "value": "sloc_123",5}

You can consume the setPricingContext hook to add the location_id context to the prices calculation:

Code
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.

Note: Learn more about prices calculation context in the Prices Calculation documentation.

Example

Code
1import { fetchShippingOptionForOrderWorkflow } from "@medusajs/medusa/core-flows"2
3fetchShippingOptionForOrderWorkflow.hooks.setPricingContext(4  (async ({}, { container }) => {5    //TODO6  })7)

Input

Handlers consuming this hook accept the following input.

inputAdditionalData & object
shipping_option_idstring
The ID of the shipping option to fetch.
currency_codestring
The currency code of the order.
order_idstring
The ID of the order.
contextCalculatedRMAShippingContext
The context of the RMA flow, which can be useful for retrieving the shipping option's price.
additional_dataRecord<string, unknown>Optional
Additional data that can be passed through the additional_data property in HTTP requests. Learn more in this documentation.
custom_amountnull | BigNumberInputOptional
The custom amount of the shipping option. If not provided, the shipping option's amount is used.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break