2020-03-06 12:27:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-03-05 14:03:48 +00:00
|
|
|
import type { Currency } from '@woocommerce/price-format';
|
|
|
|
import type { ReactElement } from 'react';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-01-20 20:35:53 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import TotalsItem from '../item';
|
|
|
|
|
2021-03-05 14:03:48 +00:00
|
|
|
interface Values {
|
|
|
|
total_items: string;
|
|
|
|
total_items_tax: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SubtotalProps {
|
|
|
|
className?: string;
|
|
|
|
currency: Currency;
|
|
|
|
values: Values | Record< string, never >;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Subtotal = ( {
|
|
|
|
currency,
|
|
|
|
values,
|
|
|
|
className,
|
|
|
|
}: SubtotalProps ): ReactElement => {
|
2020-03-06 12:27:54 +00:00
|
|
|
const { total_items: totalItems, total_items_tax: totalItemsTax } = values;
|
|
|
|
const itemsValue = parseInt( totalItems, 10 );
|
|
|
|
const itemsTaxValue = parseInt( totalItemsTax, 10 );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TotalsItem
|
2021-01-20 20:35:53 +00:00
|
|
|
className={ className }
|
2020-03-06 12:27:54 +00:00
|
|
|
currency={ currency }
|
|
|
|
label={ __( 'Subtotal', 'woo-gutenberg-products-block' ) }
|
|
|
|
value={
|
2021-04-22 11:37:27 +00:00
|
|
|
getSetting( 'displayCartPricesIncludingTax', false )
|
2020-03-06 12:27:54 +00:00
|
|
|
? itemsValue + itemsTaxValue
|
|
|
|
: itemsValue
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:29:34 +00:00
|
|
|
export default Subtotal;
|