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.

Price calc for cart

Price calc for cart

All right, so in the last video, we made it so that we can click on the Add to Cart. And that will then get, so right here, it will get the session cart ID from the cookies. And then it will get the user if there is one. If we're not logged in, user ID will be undefined, which is OK because we can use the cart as a guest. And then we get the cart, get the item that we're requesting, and then find that item in the database and put it into product. That's as far as we got. Then we just log some values. So now what we're going to want to do is add that product to the cart in the database. Now in addition to that, there's some calculations we need to do. So if we look at our cart table and we look at the fields, obviously there's nothing in here yet. But if we see the fields, there's items price, total price, shipping, and tax price, which need to get calculated. So we're going to have a calc price function. And in addition to that, we need to be able to round our numbers to two decimal…

Contents