From 98fe8fd00a1912fde1d2a93b434bda500a213c14 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Tue, 21 Mar 2023 16:15:05 +0100 Subject: [PATCH] fix(medusa): Variant update should include the id for the listeners to be able to identify the entity (#3539) * fix(medusa): Variant update should include the id for the listeners to be able to identify the entity * fix unit tests * Create brave-seahorses-film.md --- .changeset/brave-seahorses-film.md | 5 +++++ packages/medusa/src/services/__tests__/product-variant.js | 4 ++++ packages/medusa/src/services/product-variant.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/brave-seahorses-film.md diff --git a/.changeset/brave-seahorses-film.md b/.changeset/brave-seahorses-film.md new file mode 100644 index 0000000000..e1a7147da2 --- /dev/null +++ b/.changeset/brave-seahorses-film.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +Fix(medusa): Variant update should include the id for the listeners to be able to identify the entity diff --git a/packages/medusa/src/services/__tests__/product-variant.js b/packages/medusa/src/services/__tests__/product-variant.js index 07ef34d62b..dc228bb646 100644 --- a/packages/medusa/src/services/__tests__/product-variant.js +++ b/packages/medusa/src/services/__tests__/product-variant.js @@ -333,6 +333,7 @@ describe("ProductVariantService", () => { expect(productVariantRepository.update).toHaveBeenCalledWith( { id: IdMap.getId("ironman") }, { + id: IdMap.getId("ironman"), title: "new title", } ) @@ -361,6 +362,7 @@ describe("ProductVariantService", () => { expect(productVariantRepository.update).toHaveBeenCalledWith( { id: IdMap.getId("ironman") }, { + id: IdMap.getId("ironman"), title: "new title 2", } ) @@ -415,6 +417,7 @@ describe("ProductVariantService", () => { expect(productVariantRepository.update).toHaveBeenCalledWith( { id: IdMap.getId("ironman") }, { + id: IdMap.getId("ironman"), title: "new title", metadata: { testing: "this", @@ -444,6 +447,7 @@ describe("ProductVariantService", () => { expect(productVariantRepository.update).toHaveBeenCalledWith( { id: IdMap.getId("ironman") }, { + id: IdMap.getId("ironman"), inventory_quantity: 98, title: "new title", } diff --git a/packages/medusa/src/services/product-variant.ts b/packages/medusa/src/services/product-variant.ts index 6056e7a522..e368e02681 100644 --- a/packages/medusa/src/services/product-variant.ts +++ b/packages/medusa/src/services/product-variant.ts @@ -396,7 +396,10 @@ class ProductVariantService extends TransactionBaseService { // No need to update if nothing on the variant has changed if (shouldUpdate) { const { id } = variant - const rawResult = await variantRepo.update({ id }, toUpdate) + const rawResult = await variantRepo.update( + { id }, + { id, ...toUpdate } + ) result = variantRepo.create({ ...variant, ...rawResult.generatedMaps[0],