Index
Index
return (
<Fragment>
<Header />
<div className="container-fluid pt-5">
<div className="row px-xl-5">
<div className="col-lg-8 table-responsive mb-5">
<table className="table table-bordered text-center mb-0">
<thead className="bg-secondary text-dark">
<tr>
<th>Products</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Remove</th>
</tr>
</thead>
<tbody className="align-middle">
{items.map((item) => (
<tr key={item.id}>
<td className="align-middle">
<img src={item.image} alt="" style={{ width:
"50px" }} /> {item.name}
</td>
<td className="align-middle">${item.price}</td>
<td className="align-middle">
<div className="input-group quantity mx-auto"
style={{ width: "100px" }}>
<div className="input-group-btn">
<button
className="btn btn-sm btn-primary btn-minus"
onClick={() => updateQuantity(item.id, -1)}
>
<i className="fa fa-minus"></i>
</button>
</div>
<input
type="text"
className="form-control form-control-sm bg-
secondary text-center"
value={item.quantity}
readOnly
/>
<div className="input-group-btn">
<button
className="btn btn-sm btn-primary btn-plus"
onClick={() => updateQuantity(item.id, 1)}
>
<i className="fa fa-plus"></i>
</button>
</div>
</div>
</td>
<td className="align-middle">${(item.price *
item.quantity).toFixed(2)}</td>
<td className="align-middle">
<button className="btn btn-sm btn-primary"
onClick={() => removeItem(item.id)}>
<i className="fa fa-times"></i>
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
<div className="col-lg-4">
<form className="mb-5" onSubmit={(e) => e.preventDefault()}>
<div className="input-group">
<input
type="text"
className="form-control p-4"
placeholder="Coupon Code"
value={coupon}
onChange={(e) => setCoupon(e.target.value)}
/>
<div className="input-group-append">
<button className="btn btn-primary">Apply
Coupon</button>
</div>
</div>
</form>
function Index() {
const addToCart = (product) => {
const storedCart = JSON.parse(localStorage.getItem('cart')) || [];
if (existingProduct) {
// Nếu sản phẩm đã có trong giỏ, tăng số lượng lên
existingProduct.quantity += 1;
} else {
// Nếu sản phẩm chưa có, thêm mới vào giỏ
storedCart.push({ ...product, quantity: 1 });
}
return (
<Fragment>
<Header />
<Menu />
</div>
</div>
<div className="card-footer d-flex justify-content-between bg-
light border">
<a href="#"
className="btn btn-sm text-dark p-0"
onClick={() => addToCart({
id: 1,
name: "Colorful Stylish Shirt",
price: 123.00,
img: "/img/product-1.jpg" ,
style: {width: "50px"}
})}>
<i className="fas fa-shopping-cart text-primary mr-1"></i>
Add to cart
</a>
<Footer />
</Fragment>
)
}
export default Index;