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:
7
.changeset/heavy-pears-mix.md
Normal file
7
.changeset/heavy-pears-mix.md
Normal file
@@ -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
|
||||
@@ -1,9 +1,9 @@
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
IFulfillmentModuleService,
|
||||
IRegionModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
@@ -25,6 +25,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
let salesChannel
|
||||
let region
|
||||
let regionTwo
|
||||
let product
|
||||
let stockLocation
|
||||
let shippingProfile
|
||||
@@ -37,11 +38,12 @@ medusaIntegrationTestRunner({
|
||||
appContainer = getContainer()
|
||||
fulfillmentModule = appContainer.resolve(Modules.FULFILLMENT)
|
||||
regionService = appContainer.resolve(Modules.REGION)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const remoteLinkService = appContainer.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
@@ -53,6 +55,22 @@ medusaIntegrationTestRunner({
|
||||
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 = (
|
||||
await api.post(
|
||||
"/admin/sales-channels",
|
||||
@@ -79,6 +97,10 @@ medusaIntegrationTestRunner({
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
},
|
||||
{
|
||||
currency_code: "dkk",
|
||||
amount: 100,
|
||||
},
|
||||
],
|
||||
options: {
|
||||
size: "large",
|
||||
@@ -91,7 +113,7 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
).data.product
|
||||
|
||||
const stockLocation = (
|
||||
stockLocation = (
|
||||
await api.post(
|
||||
`/admin/stock-locations`,
|
||||
{
|
||||
@@ -112,7 +134,10 @@ medusaIntegrationTestRunner({
|
||||
service_zones: [
|
||||
{
|
||||
name: "Test",
|
||||
geo_zones: [{ type: "country", country_code: "us" }],
|
||||
geo_zones: [
|
||||
{ type: "country", country_code: "us" },
|
||||
{ type: "country", country_code: "dk" },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
@@ -165,35 +190,39 @@ medusaIntegrationTestRunner({
|
||||
region_id: region.id,
|
||||
amount: 1100,
|
||||
},
|
||||
{
|
||||
region_id: regionTwo.id,
|
||||
amount: 500,
|
||||
},
|
||||
],
|
||||
rules: [],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.shipping_option
|
||||
|
||||
cart = (
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
currency_code: "usd",
|
||||
email: "test@admin.com",
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
})
|
||||
|
||||
describe("GET /admin/shipping-options?cart_id=", () => {
|
||||
it("should get all shipping options for a cart successfully", async () => {
|
||||
describe("GET /store/shipping-options?cart_id=", () => {
|
||||
it("should get shipping options for a cart successfully", async () => {
|
||||
cart = (
|
||||
await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
region_id: region.id,
|
||||
sales_channel_id: salesChannel.id,
|
||||
currency_code: "usd",
|
||||
email: "test@admin.com",
|
||||
items: [
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
const resp = await api.get(
|
||||
`/store/shipping-options?cart_id=${cart.id}`,
|
||||
storeHeaders
|
||||
@@ -206,10 +235,36 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
id: shippingOption.id,
|
||||
name: "Test shipping option",
|
||||
amount: 1000,
|
||||
amount: 1100,
|
||||
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: {
|
||||
context: {
|
||||
currency_code: input.currency_code,
|
||||
region_id: input.region_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -112,6 +112,7 @@ export interface ListShippingOptionsForCartWorkflowInputDTO {
|
||||
cart_id: string
|
||||
is_return: boolean
|
||||
sales_channel_id?: string
|
||||
region_id?: string
|
||||
currency_code: string
|
||||
shipping_address: {
|
||||
city?: string
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { HttpTypes, ICartModuleService } from "@medusajs/framework/types"
|
||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { StoreGetShippingOptionsType } from "./validators"
|
||||
|
||||
export const GET = async (
|
||||
@@ -25,6 +25,7 @@ export const GET = async (
|
||||
"id",
|
||||
"sales_channel_id",
|
||||
"currency_code",
|
||||
"region_id",
|
||||
"shipping_address.city",
|
||||
"shipping_address.country_code",
|
||||
"shipping_address.province",
|
||||
@@ -37,6 +38,7 @@ export const GET = async (
|
||||
cart_id: cart.id,
|
||||
sales_channel_id: cart.sales_channel_id,
|
||||
currency_code: cart.currency_code,
|
||||
region_id: cart.region_id,
|
||||
is_return: !!is_return,
|
||||
shipping_address: {
|
||||
city: cart.shipping_address?.city,
|
||||
|
||||
Reference in New Issue
Block a user