A
A
Alexey Nevzorov2019-05-09 13:06:42
Database design
Alexey Nevzorov, 2019-05-09 13:06:42

How to store carts and other user data for guests and registrants?

The server needs information about shopping carts, favorites, viewed products and similar data. Therefore, storing in cookies and sessions is not an option. Keeping data about both kinds of users together, via a user alias (a single identifier for both) is not an option.
Chosen as a solution: create duplicate tables. Registered users are identified by an integer id, guests by uuid. This results in the following list of tables

user:      id
cart:      id, user_id, order_id
cart_item: id, cart_id, product_id
favorites: id, user_id, product_id

guest:           uuid
guest_cart:      uuid, guest_uuid
guest_cart_item: uuid, cart_uuid, product_id
guest_favorites: uuid, guest_uuid, product_id

There is no order_id in guest_cart because when creating an order (during registration or authorization), the data is transferred to the user space, and everything is deleted from guest*.
What other solutions are there to this problem? What is wrong with this implementation?
Happy holiday))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question