Chore(core-flows,order): exchange/claim add item (#8126)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-15 08:08:43 -03:00
committed by GitHub
parent 5bb870948a
commit 8d530aa7f2
27 changed files with 636 additions and 70 deletions

View File

@@ -171,7 +171,6 @@ describe("Order Exchange - Actions", function () {
id: "item_555",
unit_price: 50,
quantity: 1,
detail: {},
actions: [
{
action: "ITEM_ADD",
@@ -194,7 +193,6 @@ describe("Order Exchange - Actions", function () {
{
id: "shipping_345",
price: 5,
detail: {},
actions: [
{
action: "SHIPPING_ADD",
@@ -206,7 +204,6 @@ describe("Order Exchange - Actions", function () {
{
id: "return_shipping_345",
price: 7.5,
detail: {},
actions: [
{
action: "SHIPPING_ADD",

View File

@@ -1969,18 +1969,57 @@ export default class OrderModuleService<
}
})
const calculated = calculateOrderChange({
order: order as any,
actions: orderChange.actions,
transactions: order.transactions ?? [],
options: {
addActionReferenceToObject: true,
},
})
const { itemsToUpsert, shippingMethodsToUpsert, calculatedOrders } =
applyChangesToOrder(
[order],
{ [order.id]: orderChange.actions },
{ addActionReferenceToObject: true }
)
createRawPropertiesFromBigNumber(calculated)
const calculated = calculatedOrders[order.id]
const addedItems = {}
for (const item of calculated.order.items) {
const isExistingItem = item.id === item.detail?.item_id
if (!isExistingItem) {
addedItems[item.id] = item
}
}
if (Object.keys(addedItems).length > 0) {
const addedItemDetails = await this.listLineItems(
{ id: Object.keys(addedItems) },
{
relations: ["adjustments", "tax_lines"],
},
sharedContext
)
calculated.order.items.forEach((item, idx) => {
if (addedItems[item.id]) {
const lineItem = addedItemDetails.find((d) => d.id === item.id) as any
const actions = item.actions
delete item.actions
const newItem = itemsToUpsert.find((d) => d.item_id === item.id)!
calculated.order.items[idx] = {
...lineItem,
actions,
quantity: newItem.quantity,
detail: {
...newItem,
...item,
},
}
}
})
}
// TODO - add new shipping methods
const calcOrder = calculated.order
const calcOrder = calculated.order as any
decorateCartTotals(calcOrder as DecorateCartLikeInputDTO)
calcOrder.summary = calculated.summary