fix(medusa): Order service legacy decorate totals should add totals to items (#2667)

For some reason, probably a conflict, the legacy decorate totals does not attach the totals to the line items
https://github.com/medusajs/medusa/pull/2546/files

FIXES CORE-832

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2022-11-24 18:31:45 +00:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 2bfc55ced5
commit ed121922b0
3 changed files with 58 additions and 2 deletions
+22 -1
View File
@@ -1498,6 +1498,27 @@ class OrderService extends TransactionBaseService {
order: Order,
totalsFields: string[] = []
): Promise<Order> {
if (totalsFields.some((field) => ["subtotal", "total"].includes(field))) {
const calculationContext =
await this.totalsService_.getCalculationContext(order, {
exclude_shipping: true,
})
order.items = await Promise.all(
(order.items || []).map(async (item) => {
const itemTotals = await this.totalsService_.getLineItemTotals(
item,
order,
{
include_tax: true,
calculation_context: calculationContext,
}
)
return Object.assign(item, itemTotals)
})
)
}
for (const totalField of totalsFields) {
switch (totalField) {
case "shipping_total": {
@@ -1603,9 +1624,9 @@ class OrderService extends TransactionBaseService {
}
/**
* Calculate and attach the different total fields on the object
* @param order
* @param totalsFieldsOrConfig
* @protected
*/
async decorateTotals(
order: Order,