0
votes

I am confused a little as what should be my approach, Working on a design of shopping cart and i need to store shopping cart either in session or in database but not sure which approach would be best.here are the use case

User is not logged in and adding product to cart (Anonymous user) User is logged in and adding product to cart.

Our ShoppingCart is being saved in database and and every update/ edit in ShoppingCart is being updated in database.

Now I need to take care about creating an anonymous customer and than assign this cart to that customer so that add to cart and well checkout can be associated with this customer.

Can anyone suggest me what can be the right way to go for this?

Should I create one anonymous user in database and use it every time a request for new customer (anonymous ) is being created. Place that user in current user session. Perform any operation on cart with respect to the current session.

1

1 Answers

0
votes

The approach that you suggested for creating a single anonymous user and using that user's record for every anonymous request can cause inconsistency in the cart data.

And if you use session, the cart data will be lost as soon as user close the browser window/tab.

You can do one thing to solve your purpose, you can store the cart data in the cookies, and you can use that cookies to get the cart data even after user have closed the browser window/tab. You will get the data as far as user don't delete the cookies.