From 458dd04bbf70159ec42254e91675c7a1f1d344d8 Mon Sep 17 00:00:00 2001 From: Leonardo Benini Date: Mon, 22 Sep 2025 15:31:59 +0200 Subject: [PATCH] fix(core-flows,types,medusa): pass /store/shipping-options fields to workflow (#13527) cc @willbouch since you asked to be tagged if I opened this PR. The /store/shipping-options is one of only 2 store endpoints to not allow custom `fields` to be passed(other one is /store/returns if you guys want to add it to the backlog). This PR fixes that so that custom linked models can also be retrieved. Note: This fix reveals a bug in the next.js starter https://github.com/medusajs/nextjs-starter-medusa/blob/eac359cc8d52f1d33d8712e18e4e0f38940afb3e/src/lib/data/fulfillment.ts#L23-L24 `fields` was previously ignored, now it errors since it tries to parse the misspelled "fulfllment"(the i is missing). It worked before since both fields are already defined by default inside the workflow. So the `fields` line is totally redundant and should be removed(ideally before merging this). Maybe in the next release notes it should also warn users to remove it for those that already have a modified copy of the starter. --- .changeset/swift-forks-clean.md | 7 +++++++ .../list-shipping-options-for-cart.ts | 19 ++++++++++--------- .../core/types/src/fulfillment/workflows.ts | 6 ++++++ .../src/api/store/shipping-options/route.ts | 6 +++++- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 .changeset/swift-forks-clean.md diff --git a/.changeset/swift-forks-clean.md b/.changeset/swift-forks-clean.md new file mode 100644 index 0000000000..9a0dfe1588 --- /dev/null +++ b/.changeset/swift-forks-clean.md @@ -0,0 +1,7 @@ +--- +"@medusajs/core-flows": patch +"@medusajs/types": patch +"@medusajs/medusa": patch +--- + +fix(core-flows,types,medusa): pass /store/shipping-options fields to workflow diff --git a/packages/core/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts b/packages/core/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts index 3be6fa09c5..10119295a1 100644 --- a/packages/core/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts +++ b/packages/core/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts @@ -15,11 +15,8 @@ import { AdditionalData, ListShippingOptionsForCartWorkflowInput, } from "@medusajs/types" -import { filterObjectByKeys, isDefined } from "@medusajs/framework/utils" -import { - pricingContextResult, - shippingOptionsContextResult, -} from "../utils/schemas" +import { deduplicate, filterObjectByKeys, isDefined } from "@medusajs/framework/utils" +import { pricingContextResult, shippingOptionsContextResult } from "../utils/schemas" export const listShippingOptionsForCartWorkflowId = "list-shipping-options-for-cart" @@ -256,9 +253,9 @@ export const listShippingOptionsForCartWorkflow = createWorkflow( } ) - const shippingOptions = useRemoteQueryStep({ - entry_point: "shipping_options", - fields: [ + const fields = transform(input, ({ fields = [] }) => { + return deduplicate([ + ...fields, "id", "name", "price_type", @@ -286,7 +283,11 @@ export const listShippingOptionsForCartWorkflow = createWorkflow( "calculated_price.*", "prices.*", "prices.price_rules.*", - ], + ]) + }) + const shippingOptions = useRemoteQueryStep({ + entry_point: "shipping_options", + fields, variables: queryVariables, }).config({ name: "shipping-options-query" }) diff --git a/packages/core/types/src/fulfillment/workflows.ts b/packages/core/types/src/fulfillment/workflows.ts index 0bf99aae63..5cd9ab9556 100644 --- a/packages/core/types/src/fulfillment/workflows.ts +++ b/packages/core/types/src/fulfillment/workflows.ts @@ -236,6 +236,12 @@ export type ListShippingOptionsForCartWorkflowInput = { * If not specified, all applicable shipping options are retrieved. */ option_ids?: string[] + /** + * The fields and relations to retrieve in the shipping option. These fields + * are passed to [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query), + * so you can pass names of custom models linked to the shipping option. + */ + fields?: string[] /** * Whether to retrieve return shipping options. * By default, non-return shipping options are retrieved. diff --git a/packages/medusa/src/api/store/shipping-options/route.ts b/packages/medusa/src/api/store/shipping-options/route.ts index 26324739f3..afebe87cef 100644 --- a/packages/medusa/src/api/store/shipping-options/route.ts +++ b/packages/medusa/src/api/store/shipping-options/route.ts @@ -10,7 +10,11 @@ export const GET = async ( const workflow = listShippingOptionsForCartWorkflow(req.scope) const { result: shipping_options } = await workflow.run({ - input: { cart_id, is_return: !!is_return }, + input: { + cart_id, + is_return: !!is_return, + fields: req.queryConfig.fields + }, }) res.json({ shipping_options })