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:
1 parent
2bfc55ced5
commit
ed121922b0
3 files changed
+57
-1
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Order service legacy decorate totals should still apply the totals to the items
|
||||||
+30
@@ -432,6 +432,7 @@ Object {
|
|||||||
"claim_order_id": null,
|
"claim_order_id": null,
|
||||||
"created_at": Any<Date>,
|
"created_at": Any<Date>,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"discount_total": 0,
|
||||||
"fulfilled_quantity": 2,
|
"fulfilled_quantity": 2,
|
||||||
"has_shipping": null,
|
"has_shipping": null,
|
||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
@@ -439,10 +440,13 @@ Object {
|
|||||||
"is_return": false,
|
"is_return": false,
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"order_id": Any<String>,
|
"order_id": Any<String>,
|
||||||
|
"original_tax_total": 400,
|
||||||
|
"original_total": 2400,
|
||||||
"quantity": 2,
|
"quantity": 2,
|
||||||
"returned_quantity": 1,
|
"returned_quantity": 1,
|
||||||
"shipped_quantity": 2,
|
"shipped_quantity": 2,
|
||||||
"should_merge": true,
|
"should_merge": true,
|
||||||
|
"subtotal": 2000,
|
||||||
"swap_id": null,
|
"swap_id": null,
|
||||||
"tax_lines": Array [
|
"tax_lines": Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -456,8 +460,10 @@ Object {
|
|||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tax_total": 400,
|
||||||
"thumbnail": "",
|
"thumbnail": "",
|
||||||
"title": "Intelligent Plastic Chips",
|
"title": "Intelligent Plastic Chips",
|
||||||
|
"total": 2400,
|
||||||
"unit_price": 1000,
|
"unit_price": 1000,
|
||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
"variant": Object {
|
"variant": Object {
|
||||||
@@ -768,6 +774,7 @@ Object {
|
|||||||
"claim_order_id": null,
|
"claim_order_id": null,
|
||||||
"created_at": Any<Date>,
|
"created_at": Any<Date>,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"discount_total": 0,
|
||||||
"fulfilled_quantity": null,
|
"fulfilled_quantity": null,
|
||||||
"has_shipping": null,
|
"has_shipping": null,
|
||||||
"id": "test-item",
|
"id": "test-item",
|
||||||
@@ -775,11 +782,14 @@ Object {
|
|||||||
"is_return": false,
|
"is_return": false,
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"order_id": Any<String>,
|
"order_id": Any<String>,
|
||||||
|
"original_tax_total": 400,
|
||||||
|
"original_total": 2400,
|
||||||
"price": "10.00 USD",
|
"price": "10.00 USD",
|
||||||
"quantity": 2,
|
"quantity": 2,
|
||||||
"returned_quantity": null,
|
"returned_quantity": null,
|
||||||
"shipped_quantity": null,
|
"shipped_quantity": null,
|
||||||
"should_merge": true,
|
"should_merge": true,
|
||||||
|
"subtotal": 2000,
|
||||||
"swap_id": null,
|
"swap_id": null,
|
||||||
"tax_lines": Array [
|
"tax_lines": Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -793,8 +803,10 @@ Object {
|
|||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tax_total": 400,
|
||||||
"thumbnail": null,
|
"thumbnail": null,
|
||||||
"title": "Intelligent Plastic Chips",
|
"title": "Intelligent Plastic Chips",
|
||||||
|
"total": 2400,
|
||||||
"unit_price": 1000,
|
"unit_price": 1000,
|
||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
"variant": Object {
|
"variant": Object {
|
||||||
@@ -991,6 +1003,7 @@ Object {
|
|||||||
"claim_order_id": null,
|
"claim_order_id": null,
|
||||||
"created_at": Any<Date>,
|
"created_at": Any<Date>,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"discount_total": 0,
|
||||||
"discounted_price": "12.00 USD",
|
"discounted_price": "12.00 USD",
|
||||||
"fulfilled_quantity": 2,
|
"fulfilled_quantity": 2,
|
||||||
"has_shipping": null,
|
"has_shipping": null,
|
||||||
@@ -999,11 +1012,14 @@ Object {
|
|||||||
"is_return": false,
|
"is_return": false,
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"order_id": Any<String>,
|
"order_id": Any<String>,
|
||||||
|
"original_tax_total": 400,
|
||||||
|
"original_total": 2400,
|
||||||
"price": "12.00 USD",
|
"price": "12.00 USD",
|
||||||
"quantity": 2,
|
"quantity": 2,
|
||||||
"returned_quantity": null,
|
"returned_quantity": null,
|
||||||
"shipped_quantity": 2,
|
"shipped_quantity": 2,
|
||||||
"should_merge": true,
|
"should_merge": true,
|
||||||
|
"subtotal": 2000,
|
||||||
"swap_id": null,
|
"swap_id": null,
|
||||||
"tax_lines": Array [
|
"tax_lines": Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -1017,8 +1033,10 @@ Object {
|
|||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tax_total": 400,
|
||||||
"thumbnail": null,
|
"thumbnail": null,
|
||||||
"title": "Intelligent Plastic Chips",
|
"title": "Intelligent Plastic Chips",
|
||||||
|
"total": 2400,
|
||||||
"totals": Object {
|
"totals": Object {
|
||||||
"discount_total": 0,
|
"discount_total": 0,
|
||||||
"original_tax_total": 400,
|
"original_tax_total": 400,
|
||||||
@@ -1258,6 +1276,7 @@ Object {
|
|||||||
"claim_order_id": null,
|
"claim_order_id": null,
|
||||||
"created_at": Any<Date>,
|
"created_at": Any<Date>,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"discount_total": 0,
|
||||||
"fulfilled_quantity": 2,
|
"fulfilled_quantity": 2,
|
||||||
"has_shipping": null,
|
"has_shipping": null,
|
||||||
"id": "test-item",
|
"id": "test-item",
|
||||||
@@ -1265,10 +1284,13 @@ Object {
|
|||||||
"is_return": false,
|
"is_return": false,
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"order_id": Any<String>,
|
"order_id": Any<String>,
|
||||||
|
"original_tax_total": 400,
|
||||||
|
"original_total": 2400,
|
||||||
"quantity": 2,
|
"quantity": 2,
|
||||||
"returned_quantity": null,
|
"returned_quantity": null,
|
||||||
"shipped_quantity": 2,
|
"shipped_quantity": 2,
|
||||||
"should_merge": true,
|
"should_merge": true,
|
||||||
|
"subtotal": 2000,
|
||||||
"swap_id": null,
|
"swap_id": null,
|
||||||
"tax_lines": Array [
|
"tax_lines": Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -1282,8 +1304,10 @@ Object {
|
|||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tax_total": 400,
|
||||||
"thumbnail": "",
|
"thumbnail": "",
|
||||||
"title": "Intelligent Plastic Chips",
|
"title": "Intelligent Plastic Chips",
|
||||||
|
"total": 2400,
|
||||||
"unit_price": 1000,
|
"unit_price": 1000,
|
||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
"variant": Object {
|
"variant": Object {
|
||||||
@@ -1579,6 +1603,7 @@ Object {
|
|||||||
"claim_order_id": null,
|
"claim_order_id": null,
|
||||||
"created_at": Any<Date>,
|
"created_at": Any<Date>,
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"discount_total": 0,
|
||||||
"fulfilled_quantity": 2,
|
"fulfilled_quantity": 2,
|
||||||
"has_shipping": null,
|
"has_shipping": null,
|
||||||
"id": Any<String>,
|
"id": Any<String>,
|
||||||
@@ -1586,10 +1611,13 @@ Object {
|
|||||||
"is_return": false,
|
"is_return": false,
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"order_id": Any<String>,
|
"order_id": Any<String>,
|
||||||
|
"original_tax_total": 400,
|
||||||
|
"original_total": 2400,
|
||||||
"quantity": 2,
|
"quantity": 2,
|
||||||
"returned_quantity": null,
|
"returned_quantity": null,
|
||||||
"shipped_quantity": 2,
|
"shipped_quantity": 2,
|
||||||
"should_merge": true,
|
"should_merge": true,
|
||||||
|
"subtotal": 2000,
|
||||||
"swap_id": null,
|
"swap_id": null,
|
||||||
"tax_lines": Array [
|
"tax_lines": Array [
|
||||||
Object {
|
Object {
|
||||||
@@ -1603,8 +1631,10 @@ Object {
|
|||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tax_total": 400,
|
||||||
"thumbnail": "",
|
"thumbnail": "",
|
||||||
"title": "Intelligent Plastic Chips",
|
"title": "Intelligent Plastic Chips",
|
||||||
|
"total": 2400,
|
||||||
"unit_price": 1000,
|
"unit_price": 1000,
|
||||||
"updated_at": Any<Date>,
|
"updated_at": Any<Date>,
|
||||||
"variant": Object {
|
"variant": Object {
|
||||||
|
|||||||
@@ -1498,6 +1498,27 @@ class OrderService extends TransactionBaseService {
|
|||||||
order: Order,
|
order: Order,
|
||||||
totalsFields: string[] = []
|
totalsFields: string[] = []
|
||||||
): Promise<Order> {
|
): 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) {
|
for (const totalField of totalsFields) {
|
||||||
switch (totalField) {
|
switch (totalField) {
|
||||||
case "shipping_total": {
|
case "shipping_total": {
|
||||||
@@ -1603,9 +1624,9 @@ class OrderService extends TransactionBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Calculate and attach the different total fields on the object
|
||||||
* @param order
|
* @param order
|
||||||
* @param totalsFieldsOrConfig
|
* @param totalsFieldsOrConfig
|
||||||
* @protected
|
|
||||||
*/
|
*/
|
||||||
async decorateTotals(
|
async decorateTotals(
|
||||||
order: Order,
|
order: Order,
|
||||||
|
|||||||
Reference in new issue
Block a user