fix(core-flows): remove reservations on order edit confirm (#9477)
**What** - remove reservations from the old version of the order and create a new ones --- FIXES CC-566
This commit is contained in:
+26
-11
@@ -25,6 +25,7 @@ import {
|
|||||||
throwIfOrderChangeIsNotActive,
|
throwIfOrderChangeIsNotActive,
|
||||||
} from "../../utils/order-validation"
|
} from "../../utils/order-validation"
|
||||||
import { createOrUpdateOrderPaymentCollectionWorkflow } from "../create-or-update-order-payment-collection"
|
import { createOrUpdateOrderPaymentCollectionWorkflow } from "../create-or-update-order-payment-collection"
|
||||||
|
import { deleteReservationsByLineItemsStep } from "../../../reservation"
|
||||||
|
|
||||||
export type ConfirmOrderEditRequestWorkflowInput = {
|
export type ConfirmOrderEditRequestWorkflowInput = {
|
||||||
order_id: string
|
order_id: string
|
||||||
@@ -132,6 +133,12 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
|||||||
throw_if_key_not_found: true,
|
throw_if_key_not_found: true,
|
||||||
}).config({ name: "order-items-query" })
|
}).config({ name: "order-items-query" })
|
||||||
|
|
||||||
|
const lineItemIds = transform({ orderItems }, (data) =>
|
||||||
|
data.orderItems.items.map(({ id }) => id)
|
||||||
|
)
|
||||||
|
|
||||||
|
deleteReservationsByLineItemsStep(lineItemIds)
|
||||||
|
|
||||||
const { variants, items } = transform(
|
const { variants, items } = transform(
|
||||||
{ orderItems, orderPreview },
|
{ orderItems, orderPreview },
|
||||||
({ orderItems, orderPreview }) => {
|
({ orderItems, orderPreview }) => {
|
||||||
@@ -152,27 +159,35 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let quantity: BigNumberInput =
|
const unitPrice: BigNumberInput =
|
||||||
itemAction.raw_quantity ?? itemAction.quantity
|
|
||||||
|
|
||||||
let unit_price: BigNumberInput =
|
|
||||||
itemAction.raw_unit_price ?? itemAction.unit_price
|
itemAction.raw_unit_price ?? itemAction.unit_price
|
||||||
|
|
||||||
|
|
||||||
const updateAction = itemAction.actions!.find(
|
const updateAction = itemAction.actions!.find(
|
||||||
(a) => a.action === ChangeActionType.ITEM_UPDATE
|
(a) => a.action === ChangeActionType.ITEM_UPDATE
|
||||||
)
|
)
|
||||||
if (updateAction) {
|
|
||||||
quantity = MathBN.sub(quantity, ordItem.raw_quantity)
|
const quantity: BigNumberInput =
|
||||||
if (MathBN.lte(quantity, 0)) {
|
itemAction.raw_quantity ?? itemAction.quantity
|
||||||
return
|
|
||||||
}
|
const newQuantity = updateAction
|
||||||
|
? MathBN.sub(quantity, ordItem.raw_quantity)
|
||||||
|
: quantity
|
||||||
|
|
||||||
|
if (MathBN.lte(newQuantity, 0)) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reservationQuantity = MathBN.sub(
|
||||||
|
newQuantity,
|
||||||
|
ordItem.raw_fulfilled_quantity
|
||||||
|
)
|
||||||
|
|
||||||
allItems.push({
|
allItems.push({
|
||||||
id: ordItem.id,
|
id: ordItem.id,
|
||||||
variant_id: ordItem.variant_id,
|
variant_id: ordItem.variant_id,
|
||||||
quantity,
|
quantity: reservationQuantity,
|
||||||
unit_price,
|
unit_price: unitPrice
|
||||||
})
|
})
|
||||||
allVariants.push(ordItem.variant)
|
allVariants.push(ordItem.variant)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user