Add Items to Our Cart
Learn how to make our cart functional.
We'll cover the following...
Add items
We have a front-end that connects to our ShoppingCartChannel
with an empty shopping cart—this is not very exciting. To see the cart on-screen, we have to place an item in it. Let’s set up the front-end to add an item to our cart when we click on it. We’ll start with what we want our app.js
to look like, then we’ll implement the functions we need.
Add this function after the call to Cart.setupCartChannel
.
Press + to interact
// sneakers_23_cart/assets/js/app.jsdom.onItemClick((itemId) => {Cart.addCartItem(cartChannel, itemId)})
These functions don’t exist yet, but our code’s intent is clear. Next, we will implement onItemClick
in ...