Chore(core-flows,order): exchange/claim add item (#8126)
This commit is contained in:
committed by
GitHub
parent
5bb870948a
commit
8d530aa7f2
@@ -30,9 +30,9 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
existing = {
|
||||
id: action.details.reference_id!,
|
||||
order_id: currentOrder.id,
|
||||
return_id: action.details.return_id,
|
||||
claim_id: action.details.claim_id,
|
||||
exchange_id: action.details.exchange_id,
|
||||
return_id: action.return_id,
|
||||
claim_id: action.claim_id,
|
||||
exchange_id: action.exchange_id,
|
||||
|
||||
unit_price: action.details.unit_price,
|
||||
quantity: action.details.quantity,
|
||||
|
||||
@@ -12,22 +12,29 @@ export interface ApplyOrderChangeDTO extends OrderChangeActionDTO {
|
||||
|
||||
export function applyChangesToOrder(
|
||||
orders: any[],
|
||||
actionsMap: Record<string, any[]>
|
||||
actionsMap: Record<string, any[]>,
|
||||
options?: {
|
||||
addActionReferenceToObject?: boolean
|
||||
}
|
||||
) {
|
||||
const itemsToUpsert: OrderItem[] = []
|
||||
const shippingMethodsToUpsert: OrderShippingMethod[] = []
|
||||
const summariesToUpsert: any[] = []
|
||||
const orderToUpdate: any[] = []
|
||||
|
||||
const calculatedOrders = {}
|
||||
for (const order of orders) {
|
||||
const calculated = calculateOrderChange({
|
||||
order: order as any,
|
||||
actions: actionsMap[order.id],
|
||||
transactions: order.transactions ?? [],
|
||||
options,
|
||||
})
|
||||
|
||||
createRawPropertiesFromBigNumber(calculated)
|
||||
|
||||
calculatedOrders[order.id] = calculated
|
||||
|
||||
const version = actionsMap[order.id][0].version ?? 1
|
||||
|
||||
for (const item of calculated.order.items) {
|
||||
@@ -41,11 +48,11 @@ export function applyChangesToOrder(
|
||||
order_id: order.id,
|
||||
version,
|
||||
quantity: orderItem.quantity,
|
||||
fulfilled_quantity: orderItem.fulfilled_quantity,
|
||||
shipped_quantity: orderItem.shipped_quantity,
|
||||
return_requested_quantity: orderItem.return_requested_quantity,
|
||||
return_received_quantity: orderItem.return_received_quantity,
|
||||
return_dismissed_quantity: orderItem.return_dismissed_quantity,
|
||||
fulfilled_quantity: orderItem.fulfilled_quantity ?? 0,
|
||||
shipped_quantity: orderItem.shipped_quantity ?? 0,
|
||||
return_requested_quantity: orderItem.return_requested_quantity ?? 0,
|
||||
return_received_quantity: orderItem.return_received_quantity ?? 0,
|
||||
return_dismissed_quantity: orderItem.return_dismissed_quantity ?? 0,
|
||||
written_off_quantity: orderItem.written_off_quantity,
|
||||
metadata: orderItem.metadata,
|
||||
} as OrderItem)
|
||||
@@ -90,5 +97,6 @@ export function applyChangesToOrder(
|
||||
shippingMethodsToUpsert,
|
||||
summariesToUpsert,
|
||||
orderToUpdate,
|
||||
calculatedOrders,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
export function setActionReference(existing, action, options) {
|
||||
existing.detail ??= {}
|
||||
|
||||
existing.detail.order_id ??= action.order_id
|
||||
existing.detail.return_id ??= action.return_id
|
||||
existing.detail.claim_id ??= action.claim_id
|
||||
existing.detail.exchange_id ??= action.exchange_id
|
||||
|
||||
if (options?.addActionReferenceToObject) {
|
||||
existing.actions ??= []
|
||||
existing.actions.push(action)
|
||||
|
||||
@@ -33,6 +33,11 @@ export function formatOrder(
|
||||
}
|
||||
|
||||
mainOrder.items = mainOrder.items?.map((orderItem) => {
|
||||
const isFormatted = isDefined(orderItem.detail?.fulfilled_quantity)
|
||||
if (isFormatted) {
|
||||
return orderItem
|
||||
}
|
||||
|
||||
const detail = { ...orderItem }
|
||||
delete detail.order
|
||||
delete detail.item
|
||||
@@ -62,6 +67,10 @@ export function formatOrder(
|
||||
|
||||
if (order.shipping_methods) {
|
||||
order.shipping_methods = order.shipping_methods?.map((shippingMethod) => {
|
||||
if (shippingMethod.detail) {
|
||||
return shippingMethod
|
||||
}
|
||||
|
||||
const sm = { ...shippingMethod.shipping_method }
|
||||
|
||||
delete shippingMethod.shipping_method
|
||||
|
||||
Reference in New Issue
Block a user