diff --git a/src/Components/cart/cart.js b/src/Components/cart/cart.js new file mode 100644 index 00000000..f46d9c05 --- /dev/null +++ b/src/Components/cart/cart.js @@ -0,0 +1,128 @@ +// src/components/ShoppingCart.js +import React, { useState, useEffect } from 'react'; + +const ShoppingCart = () => { + const [cartItems, setCartItems] = useState([]); + const [totalItems, setTotalItems] = useState(0); + const [totalPrice, setTotalPrice] = useState(0); + + useEffect(() => { + const items = JSON.parse(localStorage.getItem('cartItems')) || []; + setCartItems(items); + + let itemsCount = 0; + let priceTotal = 0; + + items.forEach(item => { + itemsCount += item.quantity; + priceTotal += item.price * item.quantity; + }); + + setTotalItems(itemsCount); + setTotalPrice(priceTotal); + }, []); + + const checkout = () => { + alert('Proceeding to checkout...'); + }; + + return ( +
{item.name}
+Quantity: {item.quantity}
+Price: ${item.price * item.quantity}
+Total Items: {totalItems}
+Total Price: ${totalPrice.toFixed(2)}
+ +