Hello All! I am trying to implement a cart for a simple website that fetches from an API. So my render method looks something like this...
{somedata.map((items) => {
return (
<div key={items._id} className="col-md-3 col-12 my-2">
<div className="card h-100">
<button
className="btn btn-light"
onClick={() => addItem(items)}
>
Add to Cart
</button>
<img className="card-img-top" src={items.photo.url} alt="" />
<div className="card-body text-center">
<h3 className="card-title m-2">{items.title}</h3>
<p className="card-text">{items.description}</p>
<span className="card-text border p-3 m-2">
<b>CAD {items.price} $</b>
</span>
</div>
</div>
</div>
);
})}
And this is what my cart looks like. I am just using the example they provided us.
return (
<>
<div className="row cart_box">
<h1>Cart ({totalUniqueItems})</h1>
<ul className="cart_ul">
{items.map((item) => (
<li key={item.id} className="cart_li">
{item.quantity} x {item.title}
<div>
<img
className="img-fluid"
src={item.photo.url}
width="100px"
alt=""
/>
</div>
<button
className="btn btn-info"
onClick={() => updateItemQuantity(item.id, item.quantity - 1)}
>
-
</button>
<button
className="btn btn-info"
onClick={() => updateItemQuantity(item.id, item.quantity + 1)}
>
+
</button>
<button
className="btn btn-info"
onClick={() => removeItem(item.id)}
>
×
</button>
</li>
))}
</ul>
</div>
</>
);
}
My question is now How do I implement the total price? I do see a carttotal method there but I couldn't figure out how to implement this. Any help is appreciated thanks! :)