Ecommerce :: Shopping Cart :: Where should I store shopping cart data in a session or in a database
Of course, shopping cart data is critical data. Where to store this data depends on the user who is using your e-commerce system.
-
Users who haven't subscribed (yet) - you have to save this data to web storage, html5 gives you the option to do this. Easy to use Front End Storage that equips any browser (Cookie, Session Storage, Local Storage), User registration is required in the checkout system. After registration, you must synchronize this data with the database. Otherwise, you don't need to store this unexplored data in the database.
-
With Subscribed Users - in the database, of course. This way you can track the user's cart correctly. If the user will log in from anywhere you can show your account and "items for payment pending". And saving this data to browser storage depends on your taste.
this information can be useful and Client card for storing trading cards on the client side
a source to share
How are both? When you read your shopping cart details, check your session first. If it's there, you save the trip to the database (unless your session is supported by the database). When you write, write to session and save the database. This way you read quickly and the user doesn't lose their cart when they close the browser.
a source to share
If your shopping cart software can make the most of the abandoned carts (send reminders that they might need to come back and finish ect) and clear them from the database and do a good database build then store them in the database.
If it allows the returned user to continue with the current cart items, save them in a cookie.
If you need a new basket when you return, you might log out.
a source to share
I frequently update the bucket data to the database and keep a cached version for read requests eg. featuring a mini cart on each page. The shopping cart data should be optimized for reading. And because of the data, the basket is often small, so I would like to store it for anonymous users for several months, also store it in cookies.
a source to share
I cover him here. Make a flexible / progressive shopping cart.
Not registered
Plan A) . If using Web Storage, use it (session storage / local storage) knowing that ALL item data data can be combined into a tracking database table (with timestamps and session IDs) using AJAX. Sync and trim are key (client, tracking table). No server-side storage of individual shopping cart data is required.
If the browser is closed, the cart can be restored. Closing the browser gracefully should result in an AJAX call that will align the tracking table.
The tracking cart is not reputable (used for impact / stock reservation) as it is not an identified customer on the verge of payment. It is only if the customer hits the checkout that the items in the transport basket make a difference in terms of inventory (although there is still a lot to be done).
Plan B) . Otherwise, fall back to the session cookie-only logic. Use AJAX to read / write data to a centralized cart tracking table. The client never stores individual cart data and is not stored in session data (database driven or not). Until the customer logs in, their shopping cart data is only in the centralized cart.
If the browser is closed, the client side cart is lost forever. If the browser is closed gracefully, the items will also be removed from the watch table using an AJAX call. Otherwise, old shopping cart data in the database is truncated with uptime stamps.
Alternate Plan B) Implement a persistent customer solution using standard encrypted cookies. Thus, if the browser closes gracefully or not, it will be possible to restore the trash on the client side and update the tracking table. This will support older user agents and save them the frustration of more software and testing.
Note. ... You must anticipate and deal with the reality that session IDs will change over the life of a session. If you want to avoid fixing the session, you cannot use the same session ID over and over for every HTTP request. Hence, you must UPDATE the session ID in the main tracking table on every request. * It could be a lot of updates if many users are not logged in and they have many products in their carts.
Recorded by
When a customer logs in, you copy the contents of your cart to your cart (a regular table, not in a session). The shell game will now play between the customer, the cart table data and the main tracker cart. The content of the user's shopping cart is now constant, regardless of the user-agent. The custom car trading desk is not yet reputable.
It is only when users access the customer that the contents of the user's cart affect the availability of the inventory. Only after purchase is the actual decrease in inventory.
This last line brings up an important point. There is a difference between what is available and what is in stock. Due to the use of concurrency website, any number of people can put the same item in their cart without becoming unavailable.
If there are 10 Linux books in stock, 20 people can put 1 copy in their cart. The first ten are not a problem, but if the second ten will show a SOLD OUT message. No. What if 15 people leave, say no-mind, but never put their cart down? Everyone should see IN STOCK, but only those who got into the exit should influence accessibility. Those who pay should influence the inventory.
Therefore, when setting up product tables, be sure to include two fields for product tracking: availability and quantity. They are related, but in the ecommerce sense they are not the same.
Final Note: In a load balanced web server scenario (Amazon Web Service users will probably agree), it is more likely that the sessions will be handled by the database as it makes it easier to centralize the data. While it is possible to have networked, centralized and file / NFS based session storage in a NAS solution, this may not be desirable or optimal (latency, file locking issues).
a source to share
