medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.68k stars 2.43k forks source link

Not getting any amounts in admin/orders route #6786

Open leonlazer opened 6 months ago

leonlazer commented 6 months ago

Bug report

Describe the bug

Based on the documentation the "/admin/orders" route should have total amount, subtotal etc. in its response.

System information

Medusa version (including plugins): ^1.20.3 Node.js version: 18.19.0 Database: Operating system: Browser (if relevant):

Steps to reproduce the behavior

  1. Log into Medusa Admin Account
  2. Go to http://localhost:9000/admin/orders/

Expected behavior

It should return total, subtotal, shipping_total, tax_total and refunded_total

Screenshots

This is what I get as a response of the route:

{
    "id": "order_01HSGN642S3396YKCBAX080YDF",
    "created_at": "2024-03-21T14:03:37.270Z",
    "updated_at": "2024-03-22T08:01:43.937Z",
    "status": "pending",
    "fulfillment_status": "not_fulfilled",
    "payment_status": "captured",
    "display_id": 17,
    "cart_id": "cart_01HSGN61XP9C507JRQ1XYDHYW9",
    "customer_id": "cus_01HSG735K91CP3J4D26TGKZH72",
    "email": " xxx ",
    "region_id": "reg_01HSG6QSPDQZWSTFWKM3EB5E0A",
    "currency_code": "eur",
    "tax_rate": null,
    "draft_order_id": "dorder_01HSGN61Y3C319X1M6PEAFM3HQ",
    "canceled_at": null,
    "metadata": {},
    "no_notification": null,
    "sales_channel_id": "sc_01HSG6N8JD32T93SBE40AENFV4",
    "billing_address": { ...  },
    "claims": [],
    "customer": { ...  },
    "discounts": [],
    "fulfillments": [],
    "gift_card_transactions": [],
    "gift_cards": [],
    "items": [ ... ],
    "payments": [],
    "refunds": [],
    "region": { ... },
    "returns": [],
    "sales_channel": { ... },
    "shipping_address": { ... },
    "shipping_methods": [  { ... }  ],
    "swaps": []
}
leonlazer commented 5 months ago

For anyone struggeling with the same Issue, I "fixed" it, by adding total as an extended field of orders. So in loaders/orders.ts:

export default async function (): Promise<void> {
  const adminImports = (await import('@medusajs/medusa/dist/types/orders')) as any
  adminImports.defaultAdminOrdersFields = [
    ...adminImports.defaultAdminOrdersFields,
    'total'
  ]
}

I only needed total, so I just added this one. You could probably get the other remaining fields with this.

As this should be a default field for the list view of orders (like the documentation said) someone who's capable probably can fix this with ease. But at least it's easy to work around with this small code.