On my Ruby on Rails course I was tasked to build an e-commerce web application. In this post, I’ll cover creating a shopping cart that will keep track of products and their quantity and allow users to remove items. The full list of requirements was this:
- display a list of products to the client
- client can add any product to cart
- the cart can contain many products
- the client can remove stuff from the cart
- at the end, the client can “confirm” the cart, which clears the cart
- when a client starts adding stuff to the cart, they can come back a day later and still see their cart
- as for now, the “confirm” feature doesn’t need to do anything – in the next phase, we’ll make it an order, but for now it’s not needed
Creating and Retrieving the cart
Adding products to cart
Adding and removing products
Like most e-commerce sites, we’ve built a page where customers can look at their cart and update the quantity of items or remove them entirely. This calls for one more action in our Cart Items controller:
Now we have everything we need to keep track of products in a customer’s cart.
In my next post, I’ll cover user authentication, how to handle check out and processing orders as well as admin panel where an admin can add/manage products and prices, see existing orders and see reports of selling products in the last 30 days.