From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Section intro

Section intro

Okay, so this section is all about adding and removing items to and from the cart, and we're going to have a table in the database that represents the cart and the products within it. So we need to create a Prisma schema and a model for that. Now, since we're going to be allowing guests to add products to the cart as well, we need a way to link them to their cart. So we're going to write some code in the next auth callback to add a session cart ID, And that will link the user, the guest user, that's not logged in. It will still be able to link them to their cart in the database. Then we're going to be creating the Add to Cart component for the UI and create an action to add the item to the cart, which means adding the items to the database. And then we want to add the functionality to remove the items from the cart as well. And then we also want to make the button dynamic so that when we add to cart, it'll then show the quantity with a plus and minus on each side. And then we'll also…

Contents