T
T
Toast2014-10-27 13:05:51
Database
Toast, 2014-10-27 13:05:51

How to store product attributes in the database?

The database has a table of goods and their attributes, a separate table for storing the basket and a basket-product relationship table. The question is how and where to store the selected product attributes (for example, color, size, etc. because there is one product in the product database and id one, only the attributes are different).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
ugodrus, 2014-10-27
@ugodrus

Do you mean storing product attributes in the cart?

S
Sergey Romanov, 2014-10-27
@Serhioromano

There is a table of goods, there is a basket and there are orders. Here in the table of orders the list of goods which the person began to issue from a basket is saved. This is where you can save the attributes of the goods. Since such attributes are tied directly to each order separately.
If you link them there, after payment, only the status of the order will change, and all attributes will be saved.
It often happens that the attributes also affect the final price. For example, white can cost $5 more. So it is necessary to store attributes accordingly. Although with the style that I'm doing now, I would just save them as packed json in a separate attributes field.
But this is not always correct. For example, you are selling a property for rent. And the attribute of such a product will be the days on which this housing is already reserved. This information should be used to show the buyer free days. With such attributes, it is better to store them in separate tables but still tied to orders by order id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question