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
This commit is contained in:
Carlos R. L. Rodrigues
2024-07-09 14:45:55 +00:00
committed by GitHub
parent 4736d9e2dd
commit 2b2e2fbb3d
25 changed files with 373 additions and 57 deletions
+42
View File
@@ -835,6 +835,10 @@ export interface OrderDTO {
* The version of the order.
*/
version: number
/**
* The active order change, if any.
*/
order_change?: OrderChangeDTO
/**
* The status of the order.
*/
@@ -1191,16 +1195,54 @@ export interface OrderChangeDTO {
* The ID of the order change
*/
id: string
/**
* The version of the order change
*/
version: string
/**
* The type of the order change
*/
change_type?: "return" | "exchange" | "claim" | "edit"
/**
* The ID of the associated order
*/
order_id: string
/**
* The ID of the associated return order
*/
return_id: string
/**
* The ID of the associated exchange order
*/
exchange_id: string
/**
* The ID of the associated claim order
*/
claim_id: string
/**
* The associated order
*
* @expandable
*/
order: OrderDTO
/**
* The associated return order
*
* @expandable
*/
return_order: ReturnDTO
/**
* The associated exchange order
*
* @expandable
*/
exchange: OrderExchangeDTO
/**
* The associated claim order
*
* @expandable
*/
claim: OrderClaimDTO
/**
* The actions of the order change
+5
View File
@@ -1304,6 +1304,11 @@ export interface IOrderModuleService extends IModuleService {
*/
cancelOrderChange(orderId: string[], sharedContext?: Context): Promise<void>
previewOrderChange(
orderId: string,
sharedContext?: Context
): Promise<OrderDTO>
/**
* This method Represents the completion of an asynchronous operation
*
@@ -1,3 +1,4 @@
import { BigNumber as BigNumberJS } from "bignumber.js"
import { isDefined, trimZeros } from "../common"
import { BigNumber } from "./big-number"
@@ -11,6 +12,14 @@ export function createRawPropertiesFromBigNumber(
exclude?: string[]
} = {}
) {
const isBigNumber = (value) => {
return (
typeof value === "object" &&
isDefined(value.raw_) &&
isDefined(value.numeric_)
)
}
const stack = [{ current: obj, path: "" }]
while (stack.length > 0) {
@@ -19,7 +28,8 @@ export function createRawPropertiesFromBigNumber(
if (
current == null ||
typeof current !== "object" ||
current instanceof BigNumber
isBigNumber(current) ||
path.includes("." + prefix)
) {
continue
}
@@ -30,16 +40,17 @@ export function createRawPropertiesFromBigNumber(
)
} else {
for (const key of Object.keys(current)) {
const value = current[key]
let value = current[key]
const currentPath = path ? `${path}.${key}` : key
if (value != null && !exclude.includes(currentPath)) {
const isBigNumber =
typeof value === "object" &&
isDefined(value.raw_) &&
isDefined(value.numeric_)
const isBigNumberJS = BigNumberJS.isBigNumber(value)
if (isBigNumberJS) {
current[key] = new BigNumber(current[key])
value = current[key]
}
if (isBigNumber) {
if (isBigNumber(value)) {
const newKey = prefix + key
const newPath = path ? `${path}.${newKey}` : newKey
if (!exclude.includes(newPath)) {