fix(medusa): Missing withTransaction on calculateDiscountForLineItem (#3247)
This commit is contained in:
1 parent
4d2dc3c3a1
commit
a2cc084db8
3 files changed
+17
-7
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Generate adjustment missing transaction on calculateDiscountForLineItem
|
||||||
@@ -53,16 +53,18 @@ export default async (req, res) => {
|
|||||||
const cartService: CartService = req.scope.resolve("cartService")
|
const cartService: CartService = req.scope.resolve("cartService")
|
||||||
|
|
||||||
await manager.transaction(async (m) => {
|
await manager.transaction(async (m) => {
|
||||||
|
const cartServiceTx = cartService.withTransaction(m)
|
||||||
|
|
||||||
// Remove the line item
|
// 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
|
// 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"],
|
relations: ["payment_sessions"],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (updated.payment_sessions?.length) {
|
if (updated.payment_sessions?.length) {
|
||||||
await cartService.withTransaction(m).setPaymentSessions(id)
|
await cartServiceTx.setPaymentSessions(id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -217,11 +217,14 @@ class LineItemAdjustmentService extends TransactionBaseService {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const discountServiceTx = this.discountService.withTransaction(manager)
|
||||||
|
|
||||||
const lineItemProduct = context.variant.product_id
|
const lineItemProduct = context.variant.product_id
|
||||||
|
|
||||||
const isValid = await this.discountService
|
const isValid = await discountServiceTx.validateDiscountForProduct(
|
||||||
.withTransaction(manager)
|
discount.rule_id,
|
||||||
.validateDiscountForProduct(discount.rule_id, lineItemProduct)
|
lineItemProduct
|
||||||
|
)
|
||||||
|
|
||||||
// if discount is not valid for line item, then do nothing
|
// if discount is not valid for line item, then do nothing
|
||||||
if (!isValid) {
|
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
|
// 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()
|
lineItem.id = lineItem.id ?? new Date().getTime()
|
||||||
const amount = await this.discountService.calculateDiscountForLineItem(
|
const amount = await discountServiceTx.calculateDiscountForLineItem(
|
||||||
discount.id,
|
discount.id,
|
||||||
lineItem,
|
lineItem,
|
||||||
calculationContextData
|
calculationContextData
|
||||||
|
|||||||
Reference in new issue
Block a user