feat(modules-sdk): remote query context filter (#7153)
What: - Remote query now handles `context` keywork in the arguments to forward it as a filter to the method `list` - Pricing module `list` method returning `calculated_price` if requested as a field
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../../common/steps/use-remote-query"
|
||||
import { addShippingMethodToCartStep } from "../steps"
|
||||
import { getShippingOptionPriceSetsStep } from "../steps/get-shipping-option-price-sets"
|
||||
import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions"
|
||||
import { updateTaxLinesStep } from "../steps/update-tax-lines"
|
||||
|
||||
@@ -28,32 +27,30 @@ export const addShippingMethodToWorkflow = createWorkflow(
|
||||
return (data.input.options ?? []).map((i) => i.id)
|
||||
})
|
||||
|
||||
const priceSets = getShippingOptionPriceSetsStep({
|
||||
optionIds: optionIds,
|
||||
context: { currency_code: input.currency_code },
|
||||
})
|
||||
|
||||
const shippingOptions = useRemoteQueryStep({
|
||||
entry_point: "shipping_option",
|
||||
fields: ["id", "name"],
|
||||
fields: ["id", "name", "calculated_price.calculated_amount"],
|
||||
variables: {
|
||||
id: optionIds,
|
||||
calculated_price: {
|
||||
context: {
|
||||
currency_code: input.currency_code,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const shippingMethodInput = transform(
|
||||
{ priceSets, input, shippingOptions },
|
||||
{ input, shippingOptions },
|
||||
(data) => {
|
||||
const options = (data.input.options ?? []).map((option) => {
|
||||
const shippingOption = data.shippingOptions.find(
|
||||
(so) => so.id === option.id
|
||||
)!
|
||||
|
||||
const price = data.priceSets[option.id].calculated_amount
|
||||
|
||||
return {
|
||||
shipping_option_id: shippingOption.id,
|
||||
amount: price,
|
||||
amount: shippingOption.calculated_price.calculated_amount,
|
||||
data: option.data ?? {},
|
||||
name: shippingOption.name,
|
||||
cart_id: data.input.cart_id,
|
||||
|
||||
Reference in New Issue
Block a user