medusa
medusa copied to clipboard
Tax lines must be joined to calculate taxes
Bug report
The error message indicates a failure due to tax lines needing to be joined to calculate taxes, pointing to a deeper issue within the cart total calculation logic, particularly when handling deleted products with applied discounts.
System information
Medusa version (including plugins): 1.20.3 Node.js version: v18.19.1 Database: postgresql Operating system: ubuntu-server
Steps to reproduce the behavior
- Create a cart
- Add a product
- Apply discount to that product
- Delete product from admin
- See error from retrieving cart with totals using cartService
api-1 | Error: Tax Lines must be joined to calculate taxes
api-1 | at NewTotalsService.<anonymous> (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:213:39)
api-1 | at step (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:59:23)
api-1 | at Object.next (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:40:53)
api-1 | at /usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:34:71
api-1 | at new Promise (<anonymous>)
api-1 | at __awaiter (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:30:12)
api-1 | at NewTotalsService.getLineItemTotals_ (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:184:16)
api-1 | at NewTotalsService.<anonymous> (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:142:46)
api-1 | at step (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:59:23)
api-1 | at Object.next (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:40:53)
api-1 | at fulfilled (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:31:58)
api-1 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Expected behavior
Deleted product should be deleted from an uncompleted cart, totals should automatically works in any cases without throwing exceptions.
Screenshots
Code snippets
// Use cart service to retrieve cart WithTotals
const cart = await cartService.retrieveWithTotals(
cart_id,
{
relations: [
"region",
"customer",
"payment_sessions",
"items.variant",
"shipping_address",
],
}
);
Update: I realise something else might be at play here. I will dig into this one and get back to you.
@olivermrbl, thank you for your support. I want to confirm that the issue still occurs even when "items.tax_lines"
is added to the relations array.
Here are two more Sentry screenshots of the cart error happening in our production environment. Our current front-end workaround, which applies to creating, updating, deleting, and editing cart items following a 500 error, is far from a long-term solution. Additionally, we have implemented a "pre-check" to validate discounts, gift vouchers, price lists, etc. before transactions.
Our environment is particularly challenging due to the high volume of daily product changes, including new additions, drafts, and deletions. This dynamism highlights the need for a backend that can automatically maintain and adjust cart contents to ensure uninterrupted functionality.
I welcome any suggestions or insights on developing a more robust solution. I am ready to help in any way to deal with this problem more effectively.
@olivermrbl Any news on this?
Hi @olivermrbl, following up on this. Any news? If there's anything I can do to help, please let me know.