0
votes

I need to implement shopping cart for my website. I decided to store carts in database rather that in session. My website serves as a platform for selling items between users. That said, users can edit their own products any time.

I understand that I can't just use product ID in the cart, because user need to get whatever he put to the cart. If the product is being changed after he put it to the cart, it shouldn't affect what he ordered, correct?

How is it usually solved? Should I copy entire product to the cart? Or maybe rather save versions of particular product and link to them? Another idea would be to inform customer on checkout that the product changed.

How is it solved in popular e-commerce platforms?

1

1 Answers

1
votes

I understand that I can't just use product ID in the cart, because user need to get whatever he put to the cart. If the product is being changed after he put it to the cart, it shouldn't affect what he ordered, correct?

the product price is going to change. the inventory is going to change. if a product goes out of inventory you want the customer to know so they can make another choice. if the product price has gone up or down, the cart should reflect the current price. so that means the cart will check the product table for the product pricing and inventory at different steps before the final transaction.

as part of the cart to product lookup -- if the pricing has changed you can alert the user. just as important - if the customer has ordered quantity 4 of a product, but the inventory has gone down to just 3 of them -- you have to change the cart and make it very obvious to the customer what just happened.

there are only two things the cart is responsible for - the product id, and the quantity to be sold. anything else stored in the cart is just to make it easier to display the product on the cart page or information needed for the merchant.