Files
medusa-store/packages/modules/order/src/utils/set-action-reference.ts
Carlos R. L. Rodrigues 2b2e2fbb3d chore(order): preview order change (#8025)
What:
 - new method `previewOrderChange`
   - Calculate all the actions related to an order change.
   - Return the preview of the final Order, with all the calculated values.
   - Associate actions with items and shipping_methods they modified.

FIXES: CORE-2509
2024-07-09 14:45:55 +00:00

20 lines
580 B
TypeScript

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)
}
}
export function unsetActionReference(existing, action) {
if (Array.isArray(existing?.actions)) {
existing.actions = existing.actions.filter((a) => a.id !== action.id)
}
}