diff --git a/.changeset/thin-fans-sneeze.md b/.changeset/thin-fans-sneeze.md new file mode 100644 index 0000000000..5b88ed45c8 --- /dev/null +++ b/.changeset/thin-fans-sneeze.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): Generate adjustment missing transaction on calculateDiscountForLineItem diff --git a/packages/medusa/src/api/routes/store/carts/delete-line-item.ts b/packages/medusa/src/api/routes/store/carts/delete-line-item.ts index be0a4b09bf..c1de836022 100644 --- a/packages/medusa/src/api/routes/store/carts/delete-line-item.ts +++ b/packages/medusa/src/api/routes/store/carts/delete-line-item.ts @@ -53,16 +53,18 @@ export default async (req, res) => { const cartService: CartService = req.scope.resolve("cartService") await manager.transaction(async (m) => { + const cartServiceTx = cartService.withTransaction(m) + // Remove the line item - await cartService.withTransaction(m).removeLineItem(id, line_id) + await cartServiceTx.removeLineItem(id, line_id) // If the cart has payment sessions update these - const updated = await cartService.withTransaction(m).retrieve(id, { + const updated = await cartServiceTx.retrieve(id, { relations: ["payment_sessions"], }) if (updated.payment_sessions?.length) { - await cartService.withTransaction(m).setPaymentSessions(id) + await cartServiceTx.setPaymentSessions(id) } }) diff --git a/packages/medusa/src/services/line-item-adjustment.ts b/packages/medusa/src/services/line-item-adjustment.ts index e395ac7586..bf08fea364 100644 --- a/packages/medusa/src/services/line-item-adjustment.ts +++ b/packages/medusa/src/services/line-item-adjustment.ts @@ -217,11 +217,14 @@ class LineItemAdjustmentService extends TransactionBaseService { return [] } + const discountServiceTx = this.discountService.withTransaction(manager) + const lineItemProduct = context.variant.product_id - const isValid = await this.discountService - .withTransaction(manager) - .validateDiscountForProduct(discount.rule_id, lineItemProduct) + const isValid = await discountServiceTx.validateDiscountForProduct( + discount.rule_id, + lineItemProduct + ) // if discount is not valid for line item, then do nothing if (!isValid) { @@ -230,7 +233,7 @@ class LineItemAdjustmentService extends TransactionBaseService { // In case of a generated line item the id is not available, it is mocked instead to be used for totals calculations lineItem.id = lineItem.id ?? new Date().getTime() - const amount = await this.discountService.calculateDiscountForLineItem( + const amount = await discountServiceTx.calculateDiscountForLineItem( discount.id, lineItem, calculationContextData