chore(order): preview removed items (#8680)
This commit is contained in:
committed by
GitHub
parent
430d9a38c4
commit
99eca64c20
@@ -21,10 +21,6 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
if (MathBN.lte(existing.quantity, 0)) {
|
||||
currentOrder.items.splice(existingIndex, 1)
|
||||
}
|
||||
|
||||
return MathBN.mult(existing.unit_price, action.details.quantity)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { ChangeActionType, MathBN, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
BigNumber,
|
||||
ChangeActionType,
|
||||
MathBN,
|
||||
MedusaError,
|
||||
} from "@medusajs/utils"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
|
||||
@@ -17,15 +22,12 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_UPDATE, {
|
||||
existing.detail.quantity
|
||||
)
|
||||
|
||||
existing.quantity = action.details.quantity
|
||||
existing.detail.quantity = action.details.quantity
|
||||
const quant = new BigNumber(action.details.quantity)
|
||||
existing.quantity = quant
|
||||
existing.detail.quantity = quant
|
||||
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
if (MathBN.lte(existing.quantity, 0)) {
|
||||
currentOrder.items.splice(existingIndex, 1)
|
||||
}
|
||||
|
||||
return MathBN.mult(existing.unit_price, quantityDiff)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { OrderChangeActionDTO } from "@medusajs/types"
|
||||
import {
|
||||
ChangeActionType,
|
||||
MathBN,
|
||||
createRawPropertiesFromBigNumber,
|
||||
isDefined,
|
||||
} from "@medusajs/utils"
|
||||
@@ -42,6 +43,10 @@ export function applyChangesToOrder(
|
||||
const version = actionsMap[order.id]?.[0]?.version ?? order.version
|
||||
|
||||
for (const item of calculated.order.items) {
|
||||
if (MathBN.lte(item.quantity, 0)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const isExistingItem = item.id === item.detail?.item_id
|
||||
const orderItem = isExistingItem ? (item.detail as any) : item
|
||||
const itemId = isExistingItem ? orderItem.item_id : item.id
|
||||
|
||||
Reference in New Issue
Block a user