fix(core-flows,medusa): Include region_id in shipping option retrieval (#9929)
### What Include `region_id` when retrieving shipping options for a cart ### Why Otherwise, region-specific prices will never show in the Store API Closes CMRC-655 https://github.com/medusajs/medusa/issues/9906
This commit is contained in:
1 parent
c9a2b42252
commit
c1c85ef952
5 files changed
+76
-10
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(core-flows,medusa): Include region_id in shipping option retrieval
|
||||||
+64
-9
@@ -1,9 +1,9 @@
|
|||||||
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||||
import {
|
import {
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
IRegionModuleService,
|
IRegionModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
|
||||||
import {
|
import {
|
||||||
createAdminUser,
|
createAdminUser,
|
||||||
generatePublishableKey,
|
generatePublishableKey,
|
||||||
@@ -25,6 +25,7 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
let salesChannel
|
let salesChannel
|
||||||
let region
|
let region
|
||||||
|
let regionTwo
|
||||||
let product
|
let product
|
||||||
let stockLocation
|
let stockLocation
|
||||||
let shippingProfile
|
let shippingProfile
|
||||||
@@ -37,11 +38,12 @@ medusaIntegrationTestRunner({
|
|||||||
appContainer = getContainer()
|
appContainer = getContainer()
|
||||||
fulfillmentModule = appContainer.resolve(Modules.FULFILLMENT)
|
fulfillmentModule = appContainer.resolve(Modules.FULFILLMENT)
|
||||||
regionService = appContainer.resolve(Modules.REGION)
|
regionService = appContainer.resolve(Modules.REGION)
|
||||||
const publishableKey = await generatePublishableKey(appContainer)
|
|
||||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
const publishableKey = await generatePublishableKey(appContainer)
|
||||||
|
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||||
|
|
||||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
const remoteLinkService = appContainer.resolve(
|
const remoteLinkService = appContainer.resolve(
|
||||||
ContainerRegistrationKeys.REMOTE_LINK
|
ContainerRegistrationKeys.REMOTE_LINK
|
||||||
@@ -53,6 +55,22 @@ medusaIntegrationTestRunner({
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
regionTwo = await regionService.createRegions({
|
||||||
|
name: "Test region two",
|
||||||
|
countries: ["DK"],
|
||||||
|
currency_code: "dkk",
|
||||||
|
})
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
"/admin/price-preferences",
|
||||||
|
{
|
||||||
|
attribute: "region_id",
|
||||||
|
value: regionTwo.id,
|
||||||
|
is_tax_inclusive: true,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
salesChannel = (
|
salesChannel = (
|
||||||
await api.post(
|
await api.post(
|
||||||
"/admin/sales-channels",
|
"/admin/sales-channels",
|
||||||
@@ -79,6 +97,10 @@ medusaIntegrationTestRunner({
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
amount: 100,
|
amount: 100,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
currency_code: "dkk",
|
||||||
|
amount: 100,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
options: {
|
options: {
|
||||||
size: "large",
|
size: "large",
|
||||||
@@ -91,7 +113,7 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
).data.product
|
).data.product
|
||||||
|
|
||||||
const stockLocation = (
|
stockLocation = (
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/stock-locations`,
|
`/admin/stock-locations`,
|
||||||
{
|
{
|
||||||
@@ -112,7 +134,10 @@ medusaIntegrationTestRunner({
|
|||||||
service_zones: [
|
service_zones: [
|
||||||
{
|
{
|
||||||
name: "Test",
|
name: "Test",
|
||||||
geo_zones: [{ type: "country", country_code: "us" }],
|
geo_zones: [
|
||||||
|
{ type: "country", country_code: "us" },
|
||||||
|
{ type: "country", country_code: "dk" },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@@ -165,13 +190,20 @@ medusaIntegrationTestRunner({
|
|||||||
region_id: region.id,
|
region_id: region.id,
|
||||||
amount: 1100,
|
amount: 1100,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
region_id: regionTwo.id,
|
||||||
|
amount: 500,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
rules: [],
|
rules: [],
|
||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
).data.shipping_option
|
).data.shipping_option
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /store/shipping-options?cart_id=", () => {
|
||||||
|
it("should get shipping options for a cart successfully", async () => {
|
||||||
cart = (
|
cart = (
|
||||||
await api.post(
|
await api.post(
|
||||||
`/store/carts`,
|
`/store/carts`,
|
||||||
@@ -190,10 +222,7 @@ medusaIntegrationTestRunner({
|
|||||||
storeHeaders
|
storeHeaders
|
||||||
)
|
)
|
||||||
).data.cart
|
).data.cart
|
||||||
})
|
|
||||||
|
|
||||||
describe("GET /admin/shipping-options?cart_id=", () => {
|
|
||||||
it("should get all shipping options for a cart successfully", async () => {
|
|
||||||
const resp = await api.get(
|
const resp = await api.get(
|
||||||
`/store/shipping-options?cart_id=${cart.id}`,
|
`/store/shipping-options?cart_id=${cart.id}`,
|
||||||
storeHeaders
|
storeHeaders
|
||||||
@@ -206,10 +235,36 @@ medusaIntegrationTestRunner({
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: shippingOption.id,
|
id: shippingOption.id,
|
||||||
name: "Test shipping option",
|
name: "Test shipping option",
|
||||||
amount: 1000,
|
amount: 1100,
|
||||||
price_type: "flat",
|
price_type: "flat",
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cart = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts/${cart.id}`,
|
||||||
|
{
|
||||||
|
region_id: regionTwo.id,
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
const secondResp = await api.get(
|
||||||
|
`/store/shipping-options?cart_id=${cart.id}`,
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(secondResp.data.shipping_options).toHaveLength(1)
|
||||||
|
expect(secondResp.data.shipping_options[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: shippingOption.id,
|
||||||
|
name: "Test shipping option",
|
||||||
|
amount: 500,
|
||||||
|
price_type: "flat",
|
||||||
|
is_tax_inclusive: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
|||||||
calculated_price: {
|
calculated_price: {
|
||||||
context: {
|
context: {
|
||||||
currency_code: input.currency_code,
|
currency_code: input.currency_code,
|
||||||
|
region_id: input.region_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ export interface ListShippingOptionsForCartWorkflowInputDTO {
|
|||||||
cart_id: string
|
cart_id: string
|
||||||
is_return: boolean
|
is_return: boolean
|
||||||
sales_channel_id?: string
|
sales_channel_id?: string
|
||||||
|
region_id?: string
|
||||||
currency_code: string
|
currency_code: string
|
||||||
shipping_address: {
|
shipping_address: {
|
||||||
city?: string
|
city?: string
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows"
|
import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows"
|
||||||
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
import { HttpTypes, ICartModuleService } from "@medusajs/framework/types"
|
import { HttpTypes, ICartModuleService } from "@medusajs/framework/types"
|
||||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
||||||
import { StoreGetShippingOptionsType } from "./validators"
|
import { StoreGetShippingOptionsType } from "./validators"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
@@ -25,6 +25,7 @@ export const GET = async (
|
|||||||
"id",
|
"id",
|
||||||
"sales_channel_id",
|
"sales_channel_id",
|
||||||
"currency_code",
|
"currency_code",
|
||||||
|
"region_id",
|
||||||
"shipping_address.city",
|
"shipping_address.city",
|
||||||
"shipping_address.country_code",
|
"shipping_address.country_code",
|
||||||
"shipping_address.province",
|
"shipping_address.province",
|
||||||
@@ -37,6 +38,7 @@ export const GET = async (
|
|||||||
cart_id: cart.id,
|
cart_id: cart.id,
|
||||||
sales_channel_id: cart.sales_channel_id,
|
sales_channel_id: cart.sales_channel_id,
|
||||||
currency_code: cart.currency_code,
|
currency_code: cart.currency_code,
|
||||||
|
region_id: cart.region_id,
|
||||||
is_return: !!is_return,
|
is_return: !!is_return,
|
||||||
shipping_address: {
|
shipping_address: {
|
||||||
city: cart.shipping_address?.city,
|
city: cart.shipping_address?.city,
|
||||||
|
|||||||
Reference in new issue
Block a user