@
@
@shuttle2011-01-24 22:06:21
Algorithms
@shuttle, 2011-01-24 22:06:21

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

8 answer(s)
B
Bartez, 2011-01-24
@Bartez

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.

M
mind3, 2016-10-28
@mind3

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:

  • the goods in the basket will remain when the user re-enters (the main thing is not to forget when setting the cookie, the storage time you need to set)
  • it becomes possible to collect statistics on the baskets of users who have not made an order

H
homm, 2011-01-24
@homm

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.

B
Bartez, 2011-01-24
@Bartez

homm, “I keep the cart for a month in session”
How is that?

S
Shvonder, 2011-01-27
@Shvonder

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

Z
zenmoon, 2011-01-24
@zenmoon

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.

Y
yats, 2013-06-04
@yats

Cart - we store information about the goods in the database - this is convenient. We display the necessary information in the session.

L
lstdmi, 2019-01-27
@lstdmi

I decided to try adding to the basket through cookies, and when already when requesting the basket page or other pages, read the cookies on the server and immediately put them in the server session .. well, clear the browser cookies on the server ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question