fix(medusa): ignore region_id update w/o value change (#4751)
This commit is contained in:
5
.changeset/selfish-pugs-cheer.md
Normal file
5
.changeset/selfish-pugs-cheer.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ignore region_id update w/o value change
|
||||||
@@ -2690,6 +2690,43 @@ describe("/store/carts", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("ignore region update if value didn't change", () => {
|
||||||
|
afterEach(async () => {
|
||||||
|
await doAfterEach()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("has no side-effects when updating region with no change", async () => {
|
||||||
|
const region = await simpleRegionFactory(dbConnection, {
|
||||||
|
countries: ["us", "ca"],
|
||||||
|
})
|
||||||
|
const product = await simpleProductFactory(dbConnection)
|
||||||
|
const cart = await simpleCartFactory(dbConnection, {
|
||||||
|
region: region.id,
|
||||||
|
line_items: [{ variant_id: product.variants[0].id, quantity: 1 }],
|
||||||
|
shipping_address: {
|
||||||
|
country_code: "us",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const { data: preconditionData } = await api.get(
|
||||||
|
`/store/carts/${cart.id}`
|
||||||
|
)
|
||||||
|
const { data, status } = await api
|
||||||
|
.post(`/store/carts/${cart.id}`, {
|
||||||
|
region_id: region.id,
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(status).toEqual(200)
|
||||||
|
expect(data.cart.shipping_address.country_code).toEqual("us")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("calculated prices for shipping option", () => {
|
describe("calculated prices for shipping option", () => {
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await doAfterEach()
|
await doAfterEach()
|
||||||
|
|||||||
@@ -765,9 +765,9 @@ class CartService extends TransactionBaseService {
|
|||||||
|
|
||||||
return await this.atomicPhase_(
|
return await this.atomicPhase_(
|
||||||
async (transactionManager: EntityManager) => {
|
async (transactionManager: EntityManager) => {
|
||||||
let cart = await this.retrieve(cartId, {
|
let cart = await this.retrieve(cartId, {
|
||||||
select,
|
select,
|
||||||
relations: ["shipping_methods"]
|
relations: ["shipping_methods"],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.featureFlagRouter_.isFeatureEnabled("sales_channels")) {
|
if (this.featureFlagRouter_.isFeatureEnabled("sales_channels")) {
|
||||||
@@ -1112,7 +1112,7 @@ class CartService extends TransactionBaseService {
|
|||||||
await this.updateUnitPrices_(cart, data.region_id, data.customer_id)
|
await this.updateUnitPrices_(cart, data.region_id, data.customer_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDefined(data.region_id)) {
|
if (isDefined(data.region_id) && cart.region_id !== data.region_id) {
|
||||||
const shippingAddress =
|
const shippingAddress =
|
||||||
typeof data.shipping_address !== "string"
|
typeof data.shipping_address !== "string"
|
||||||
? data.shipping_address
|
? data.shipping_address
|
||||||
|
|||||||
Reference in New Issue
Block a user