#shopping cart logic, before and after log in.

11 messages · Page 1 of 1 (latest)

earnest marlin
#

i have different components for the main catalog and the product details. I want the user to be able to add/remove to cart, and maintain state between views without using session/local storage. I was thinking, since I already created a service to handle the log in process, I'd store the "guest" cart and the "user" cart there. Is there a better way? should I keep the cart as an offcanvas modal in the app-module html?

night pebble
#

since I already created a service to handle the log in process, I'd store the "guest" cart and the "user" cart there
Technically you can and yes it will work. But you probably want a seperate service (or maybe even a redux store) since your service that handles login seems kind of awkward if you also put the cart information in there.

earnest marlin
small wigeon
#

I suggest using a session cookie

earnest marlin
small wigeon
#

Store the users cart details in whatever db you are using. You use send a custom cookie (session) to associate to each device. This custom cookie is then used to pull the users cart items.

#

Hopefully you understand my drift

high crypt
#

and maintain state between views without using session/local storage
Why ?

#

That would mean a refresh would clear my cart, which I find very frustrating.

#

I think at the very least, you should ensure the cart survives page refreshes. And if you want to share the same cart on multiple devices, you can look into moving it to the server. Personally, I wouldnt tie it to a server session if it's just for a single device.