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 19:31:45 +01:00
committed by GitHub
parent 2bfc55ced5
commit ed121922b0
3 changed files with 58 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Order service legacy decorate totals should still apply the totals to the items

View File

@@ -432,6 +432,7 @@ Object {
"claim_order_id": null,
"created_at": Any<Date>,
"description": "",
"discount_total": 0,
"fulfilled_quantity": 2,
"has_shipping": null,
"id": Any<String>,
@@ -439,10 +440,13 @@ Object {
"is_return": false,
"metadata": null,
"order_id": Any<String>,
"original_tax_total": 400,
"original_total": 2400,
"quantity": 2,
"returned_quantity": 1,
"shipped_quantity": 2,
"should_merge": true,
"subtotal": 2000,
"swap_id": null,
"tax_lines": Array [
Object {
@@ -456,8 +460,10 @@ Object {
"updated_at": Any<Date>,
},
],
"tax_total": 400,
"thumbnail": "",
"title": "Intelligent Plastic Chips",
"total": 2400,
"unit_price": 1000,
"updated_at": Any<Date>,
"variant": Object {
@@ -768,6 +774,7 @@ Object {
"claim_order_id": null,
"created_at": Any<Date>,
"description": "",
"discount_total": 0,
"fulfilled_quantity": null,
"has_shipping": null,
"id": "test-item",
@@ -775,11 +782,14 @@ Object {
"is_return": false,
"metadata": null,
"order_id": Any<String>,
"original_tax_total": 400,
"original_total": 2400,
"price": "10.00 USD",
"quantity": 2,
"returned_quantity": null,
"shipped_quantity": null,
"should_merge": true,
"subtotal": 2000,
"swap_id": null,
"tax_lines": Array [
Object {
@@ -793,8 +803,10 @@ Object {
"updated_at": Any<Date>,
},
],
"tax_total": 400,
"thumbnail": null,
"title": "Intelligent Plastic Chips",
"total": 2400,
"unit_price": 1000,
"updated_at": Any<Date>,
"variant": Object {
@@ -991,6 +1003,7 @@ Object {
"claim_order_id": null,
"created_at": Any<Date>,
"description": "",
"discount_total": 0,
"discounted_price": "12.00 USD",
"fulfilled_quantity": 2,
"has_shipping": null,
@@ -999,11 +1012,14 @@ Object {
"is_return": false,
"metadata": null,
"order_id": Any<String>,
"original_tax_total": 400,
"original_total": 2400,
"price": "12.00 USD",
"quantity": 2,
"returned_quantity": null,
"shipped_quantity": 2,
"should_merge": true,
"subtotal": 2000,
"swap_id": null,
"tax_lines": Array [
Object {
@@ -1017,8 +1033,10 @@ Object {
"updated_at": Any<Date>,
},
],
"tax_total": 400,
"thumbnail": null,
"title": "Intelligent Plastic Chips",
"total": 2400,
"totals": Object {
"discount_total": 0,
"original_tax_total": 400,
@@ -1258,6 +1276,7 @@ Object {
"claim_order_id": null,
"created_at": Any<Date>,
"description": "",
"discount_total": 0,
"fulfilled_quantity": 2,
"has_shipping": null,
"id": "test-item",
@@ -1265,10 +1284,13 @@ Object {
"is_return": false,
"metadata": null,
"order_id": Any<String>,
"original_tax_total": 400,
"original_total": 2400,
"quantity": 2,
"returned_quantity": null,
"shipped_quantity": 2,
"should_merge": true,
"subtotal": 2000,
"swap_id": null,
"tax_lines": Array [
Object {
@@ -1282,8 +1304,10 @@ Object {
"updated_at": Any<Date>,
},
],
"tax_total": 400,
"thumbnail": "",
"title": "Intelligent Plastic Chips",
"total": 2400,
"unit_price": 1000,
"updated_at": Any<Date>,
"variant": Object {
@@ -1579,6 +1603,7 @@ Object {
"claim_order_id": null,
"created_at": Any<Date>,
"description": "",
"discount_total": 0,
"fulfilled_quantity": 2,
"has_shipping": null,
"id": Any<String>,
@@ -1586,10 +1611,13 @@ Object {
"is_return": false,
"metadata": null,
"order_id": Any<String>,
"original_tax_total": 400,
"original_total": 2400,
"quantity": 2,
"returned_quantity": null,
"shipped_quantity": 2,
"should_merge": true,
"subtotal": 2000,
"swap_id": null,
"tax_lines": Array [
Object {
@@ -1603,8 +1631,10 @@ Object {
"updated_at": Any<Date>,
},
],
"tax_total": 400,
"thumbnail": "",
"title": "Intelligent Plastic Chips",
"total": 2400,
"unit_price": 1000,
"updated_at": Any<Date>,
"variant": Object {
@@ -2446,4 +2476,4 @@ Object {
"tracking_links": Array [],
"tracking_number": "",
}
`;
`;

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,