Not logged in: save the cookie when adding to the shopping cart, and the shopping cart displays the cookie content After logging in: when logging in, take the cookie and save it to the database shopping cart table, handle the duplication of cookies and tables, clear the cookies, and the shopping cart displays the contents of the table. Save it directly to the table when adding to the shopping cart
As for the stored data, it depends on the design of the product. The necessary ones include: product id, purchase quantity, and product attributes selected by the user (if any). If the product is deleted and only a field is changed, these data should meet the needs. There are more user IDs in the table than cookies Another note: If the record is really deleted when the product is deleted, you can consider storing multiple product names, product pictures, etc.
Not logged in: save the cookie when adding to the shopping cart, and the shopping cart displays the cookie content
After logging in: when logging in, take the cookie and save it to the database shopping cart table, handle the duplication of cookies and tables, clear the cookies, and the shopping cart displays the contents of the table. Save it directly to the table when adding to the shopping cart
As for the stored data, it depends on the design of the product. The necessary ones include: product id, purchase quantity, and product attributes selected by the user (if any). If the product is deleted and only a field is changed, these data should meet the needs. There are more user IDs in the table than cookies
Another note: If the record is really deleted when the product is deleted, you can consider storing multiple product names, product pictures, etc.
Just cache the user’s shopping information