diff --git a/src/modules/common/components/cart-totals/index.tsx b/src/modules/common/components/cart-totals/index.tsx index 9a7c53ea4..41302a844 100644 --- a/src/modules/common/components/cart-totals/index.tsx +++ b/src/modules/common/components/cart-totals/index.tsx @@ -2,6 +2,7 @@ import { convertToLocale } from "@lib/util/money" import React from "react" +import { Badge } from "@medusajs/ui" type CartTotalsProps = { totals: { @@ -12,7 +13,11 @@ type CartTotalsProps = { discount_total?: number | null gift_card_total?: number | null currency_code: string + item_subtotal?: number | null + item_total?: number | null shipping_subtotal?: number | null + shipping_methods?: {adjustments?: {amount: number}[]}[] + items?: {adjustments?: {amount: number}[]}[] } } @@ -20,42 +25,57 @@ const CartTotals: React.FC = ({ totals }) => { const { currency_code, total, - subtotal, tax_total, - discount_total, gift_card_total, + item_subtotal, + item_total, shipping_subtotal, + shipping_total, + shipping_methods, + items } = totals + const totalItemDiscount = items?.flatMap(i => i.adjustments).reduce((acc, curr) => (curr?.amount || 0) + acc, 0) + const totalShippingDiscount = shipping_methods?.flatMap(sm => sm.adjustments).reduce((acc, curr) => (curr?.amount || 0) + acc, 0) + return (
- - Subtotal (excl. shipping and taxes) - - - {convertToLocale({ amount: subtotal ?? 0, currency_code })} - -
- {!!discount_total && ( -
- Discount + Subtotal (excl. shipping and taxes) +
+ + {convertToLocale({ amount: item_subtotal ?? 0, currency_code })} + + {!!totalItemDiscount && ( +
- -{" "} - {convertToLocale({ amount: discount_total ?? 0, currency_code })} + {convertToLocale({ amount: item_total ?? 0, currency_code })} +
+ )}
- )} +
Shipping - - {convertToLocale({ amount: shipping_subtotal ?? 0, currency_code })} - +
+ + {convertToLocale({ amount: shipping_subtotal ?? 0, currency_code })} + + {!!totalShippingDiscount && ( + + {convertToLocale({ amount: shipping_total ?? 0, currency_code })} + + )} +
Taxes