On the server you need information about the baskets, favorites, viewed products and similar data. Therefore, to store in cookies and sessions is not an option. Storing data about both types of users together, via a user alias (a common identifier for both) is not an option.

The solution chosen is: create duplicate tables. Registered users are identified by an integer id, guests by uuid. The following list of tables is obtained.

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 

In guest_cart missing, since when creating an order (during registration or authorization), the data is transferred to the user space, and from guest* everything is deleted.

What are some other solutions to this problem? What is bad about this implementation?

Happy holiday))

    0