From d81236a6391927d85e0d5ed60c57f1ca379b6b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 20 Jun 2023 14:41:37 +0200 Subject: [PATCH] Mini-Cart: don't include shipping price (#9914) --- assets/js/blocks/mini-cart/utils/data.ts | 12 ++++++++---- assets/js/blocks/mini-cart/utils/test/data.ts | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/assets/js/blocks/mini-cart/utils/data.ts b/assets/js/blocks/mini-cart/utils/data.ts index a4d1ea62611..55734b2d259 100644 --- a/assets/js/blocks/mini-cart/utils/data.ts +++ b/assets/js/blocks/mini-cart/utils/data.ts @@ -10,11 +10,15 @@ import { CartResponse, isBoolean } from '@woocommerce/types'; import { getSettingWithCoercion } from '@woocommerce/settings'; const getPrice = ( cartResponse: CartResponse, showIncludingTax: boolean ) => { - const currency = getCurrencyFromPriceResponse( cartResponse.totals ); + const { totals } = cartResponse; + const currency = getCurrencyFromPriceResponse( totals ); - return showIncludingTax - ? formatPrice( cartResponse.totals.total_price, currency ) - : formatPrice( cartResponse.totals.total_items, currency ); + const subTotal = showIncludingTax + ? parseInt( totals.total_items, 10 ) + + parseInt( totals.total_items_tax, 10 ) + : parseInt( totals.total_items, 10 ); + + return formatPrice( subTotal, currency ); }; export const updateTotals = ( totals: [ string, number ] | undefined ) => { diff --git a/assets/js/blocks/mini-cart/utils/test/data.ts b/assets/js/blocks/mini-cart/utils/test/data.ts index 7c02da72053..341a590f813 100644 --- a/assets/js/blocks/mini-cart/utils/test/data.ts +++ b/assets/js/blocks/mini-cart/utils/test/data.ts @@ -19,8 +19,9 @@ const responseMock = { ok: true, json: async () => ( { totals: { - total_price: '1600', + total_price: '1800', total_items: '1400', + total_items_tax: '200', currency_code: 'USD', currency_symbol: '$', currency_minor_unit: 2, @@ -34,8 +35,9 @@ const responseMock = { } as Response; const localStorageMock = { totals: { - total_price: '1600', + total_price: '1800', total_items: '1400', + total_items_tax: '200', currency_code: 'USD', currency_symbol: '$', currency_minor_unit: 2,