Finally making my way through the book this weekend, going through the first tests and cart development. Am I to understand that a user looking to purchase tickets must already be a registered, logged-in user of the Snow Globe Theater’s website before adding a ticket to their cart?
Yes, the code in the example requires a login to put something in the cart. That isn’t the only way to do it, but it does simplify the code to be able to assume that there’s a live user id for each cart.
If you want to let people use the cart without being logged in, then you need to associate the column with the session or a cookie. Then when the user does log in, you need a post-login action that associates an active cart with the user so that the cart carries forward.
In most cases, I’d recommend having the user be logged in before purchase. I know that some sites allow guest purchases, I just think that’s going to be a pain for long term reporting purposes.
I agree that it’s a pain, but from a UX perspective, I can’t think of any stores that require you to be a logged in user just to add something to your cart. It’s such a different experience from what customers online are used to, that I would be afraid to roll this out on any production website. Studies show that about 30% of users abandon their cart when asked to log-in up front. But that’s after they’ve already been able to add something to their cart without logging in. I can’t imagine the impact on a store that requires the user to log in before they’ve even started shopping.
I’m going to try to do as you suggested and combine the approach with a cookie-based one. Thanks for replying so quickly!
Yeah, sometimes it comes down to the needs of the book tutorial to focus on the most relevant code paths. This might make a good supplemental blog post or something, though.
Definitely! Honestly, I bet there’s a whole other book just in shopping cart development. Or maybe people are just using shopify or spree these days, I have no idea…
Let us know if you do end up writing that post! And thanks again!