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
eac359cc8d/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.
This commit is contained in:
7
.changeset/swift-forks-clean.md
Normal file
7
.changeset/swift-forks-clean.md
Normal file
@@ -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
|
||||||
@@ -15,11 +15,8 @@ import {
|
|||||||
AdditionalData,
|
AdditionalData,
|
||||||
ListShippingOptionsForCartWorkflowInput,
|
ListShippingOptionsForCartWorkflowInput,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { filterObjectByKeys, isDefined } from "@medusajs/framework/utils"
|
import { deduplicate, filterObjectByKeys, isDefined } from "@medusajs/framework/utils"
|
||||||
import {
|
import { pricingContextResult, shippingOptionsContextResult } from "../utils/schemas"
|
||||||
pricingContextResult,
|
|
||||||
shippingOptionsContextResult,
|
|
||||||
} from "../utils/schemas"
|
|
||||||
|
|
||||||
export const listShippingOptionsForCartWorkflowId =
|
export const listShippingOptionsForCartWorkflowId =
|
||||||
"list-shipping-options-for-cart"
|
"list-shipping-options-for-cart"
|
||||||
@@ -256,9 +253,9 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const shippingOptions = useRemoteQueryStep({
|
const fields = transform(input, ({ fields = [] }) => {
|
||||||
entry_point: "shipping_options",
|
return deduplicate([
|
||||||
fields: [
|
...fields,
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"name",
|
||||||
"price_type",
|
"price_type",
|
||||||
@@ -286,7 +283,11 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
|||||||
"calculated_price.*",
|
"calculated_price.*",
|
||||||
"prices.*",
|
"prices.*",
|
||||||
"prices.price_rules.*",
|
"prices.price_rules.*",
|
||||||
],
|
])
|
||||||
|
})
|
||||||
|
const shippingOptions = useRemoteQueryStep({
|
||||||
|
entry_point: "shipping_options",
|
||||||
|
fields,
|
||||||
variables: queryVariables,
|
variables: queryVariables,
|
||||||
}).config({ name: "shipping-options-query" })
|
}).config({ name: "shipping-options-query" })
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,12 @@ export type ListShippingOptionsForCartWorkflowInput = {
|
|||||||
* If not specified, all applicable shipping options are retrieved.
|
* If not specified, all applicable shipping options are retrieved.
|
||||||
*/
|
*/
|
||||||
option_ids?: string[]
|
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.
|
* Whether to retrieve return shipping options.
|
||||||
* By default, non-return shipping options are retrieved.
|
* By default, non-return shipping options are retrieved.
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ export const GET = async (
|
|||||||
|
|
||||||
const workflow = listShippingOptionsForCartWorkflow(req.scope)
|
const workflow = listShippingOptionsForCartWorkflow(req.scope)
|
||||||
const { result: shipping_options } = await workflow.run({
|
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 })
|
res.json({ shipping_options })
|
||||||
|
|||||||
Reference in New Issue
Block a user