Skip to content

Commit

Permalink
fix: product qty
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and kris-liu-smile committed Nov 22, 2022
1 parent f9b2ef8 commit a7448b1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/storefront/src/pages/orderDetail/shared/B2BOrderData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ const getPaymentData = (data: B2BOrderData) => {
}
}

const handleProductQuantity = (data: B2BOrderData) => {
const {
products,
} = data

const newProducts: any[] = []

products.forEach((product: any) => {
const productIndex = newProducts.findIndex((item) => +item.variant_id === +product.variant_id)

if (productIndex === -1) {
newProducts.push(product)
} else {
const existedProduct = newProducts[productIndex]

newProducts[productIndex] = {
...existedProduct,
quantity: +existedProduct.quantity + +product.quantity,
}
}
})

return newProducts
}

export const convertB2BOrderDetails = (data: B2BOrderData) => ({
shippings: getOrderShipping(data),
history: data.orderHistoryEvent || [],
Expand All @@ -144,6 +169,6 @@ export const convertB2BOrderDetails = (data: B2BOrderData) => ({
orderSummary: getOrderSummary(data),
payment: getPaymentData(data),
orderComments: data.customerMessage,
products: data.products,
products: handleProductQuantity(data),
orderId: +data.id,
})

0 comments on commit a7448b1

Please sign in to comment.