Answer the question
In order to leave comments, you need to log in
Online store cart: data in cookies, or in the database
I can't decide where is the best place to store data about the user's pending purchases in the online store?
Put the goods of the basket in the session, in cookies, or store them in a separate table in the database, which is periodically cleared ..?
I went through large stores (amazon, ozon) - in cookies they leave only the session identifier.
Answer the question
In order to leave comments, you need to log in
It used to be customary to store the cart in cookies.
Now a good practice is to store the cart in the database.
Advantages of storage in the database:
1) The basket can be stored for as long as you like.
2) The cart is not lost if the customer logged in from a different browser/computer.
As far as I remember, the session works until the browser is closed and depending on the settings on the server.
Minuses:
It is better to use this practice:
Of the advantages of this approach:
I store the basket for a month in the session. There is no registration, so the 2nd item listed by Bartez is not possible.
If, in addition to the number of products and id, you need to store more configurations of products, or other information, it will be much more convenient to keep it in the language structures serialized in the session than in the base tables.
And I store in cookies and nothing, it's fine. The cons have been stated. Pros - instant addition to the cart and instant change in the number of goods / amount. I store it as json. In order for the cookie to overflow, you need to put a lot in the basket
It is better to store the basket on the server side. Base, NoSQL, files - this is already a choice. I would advise Redis, for example. There is already a tracking of the relevance of the data.
Cart - we store information about the goods in the database - this is convenient. We display the necessary information in the session.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question