Shopping Cart: Local Storage vs. Session Storage

I am about to start on this tutorial:

I have read the difference between local and session storage. My question, before I start, is there a difference in the tutorial if I use session storage and will that still work for checkout purposes?

I really don’t care about storing the cart for later use. I would prefer it be cleared each time.

Use Local Storage (data store)

Then I would have to figure out a way to prevent users from accidentally/intentionally order tickets to play dates that are no longer available. Hmmm.

For example if a play is on September 1st, 2020 the option to buy should not be available after August 31, 2020. Or if a play has been sold out and not available the person could still have that play stored in their cart for purchase. I can’t have that.

That’s fairly straight forward, just have a condition step at the beginning of your checkout server action that checks that the ticket/show date is not less than/before today’s date (NOW or NOW_UTC), if it is you can throw an error status to the client side and it won’t checkout.

Is there any disadvantage to using session storage instead of local? I would have thought it might be more appropriate in this case.

The only difference, as explained in the tutorial:

Local Storage vs Session Storage

You can select between storing your data in the browser local storage or session storage. What are differences?

Local Storage

The Local Storage stores data with no expiration date, and gets cleared only through JavaScript (Wappler dynamic events) or clearing the Browser cache / Locally Stored Data.

Session Storage

The Session Storage stores data only for a session, so the data is stored until the browser or the tab is closed.

Yep, I read that. That’s why I asked if the tutorial is still the same and if Stripe Checkout will work if I use Sessions instead. I don’t want tp get my way through it only to find out it won’t work with Stripe Checkout.

Yes it’s the same.

1 Like

Mainly session expiry and also that most of the tutorials are centred around local storage. As Teo pointed out it would work either way. I have my sessions set to short periods for security so that’s why I went with local storage.

I love the fact with local storage that you can see exactly what’s stored by using the browser console so makes testing so much easier.

I agree this is very useful, but as far as I know, it works exactly the same with session storage - you just click Session Storage instead of Local Storage in the browser developer tools.

2 Likes

Doh! Yep, can’t believe I overlooked that!

2 Likes