fix showing 0.00 for cart total
This commit is contained in:
parent
2cc56f7ad7
commit
488aa4c03d
|
|
@ -1,4 +1,4 @@
|
|||
import React, { Fragment, useContext } from 'react';
|
||||
import React, { Fragment, useContext, useEffect } from 'react';
|
||||
import { isIterableArray } from '../../../helpers/utils';
|
||||
import { Col, Row } from 'reactstrap';
|
||||
import ShoppingCartItem from './ShoppingCartItem';
|
||||
|
|
@ -7,8 +7,12 @@ import { useShoppingCart } from '../../../hooks/useShoppingCart';
|
|||
|
||||
const ShoppingCartTable = ({ shoppingCart, loading, onRemoveItem }) => {
|
||||
const { currency } = useContext(AppContext);
|
||||
const { cartTotal, cartSubTotal, cartTax } = useShoppingCart();
|
||||
|
||||
const { getCartItems, cartTotal, cartSubTotal, cartTax } = useShoppingCart();
|
||||
|
||||
useEffect(() => {
|
||||
getCartItems();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{loading ? (
|
||||
|
|
|
|||
|
|
@ -7,16 +7,12 @@ export const useShoppingCart = () => {
|
|||
const [error, setError] = useState(null);
|
||||
const TAX_RATE = 0.1;
|
||||
|
||||
// useEffect(() => {
|
||||
// getCartItems();
|
||||
// }, []);
|
||||
|
||||
const cartTotal = useMemo(() => {
|
||||
//calculate total price
|
||||
if(shoppingCart.length === 0){
|
||||
return 0.00;
|
||||
}
|
||||
const totalPrice = shoppingCart.reduce((acc, item) => acc + parseFloat(item.product_info.total_price), 0.00);
|
||||
const totalPrice = shoppingCart.reduce((acc, item) => acc + parseFloat(item.product_info.real_price), 0.00);
|
||||
return totalPrice;
|
||||
}, [shoppingCart]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue