D
D
Dmitry Yakovlev2018-10-20 16:47:24
MySQL
Dmitry Yakovlev, 2018-10-20 16:47:24

How to design products with variable prices?

There are goods and there are attributes, some attributes change the cost of goods, some do not.
Example:
TV is a product, diagonal is an attribute. 40 inches (attribute value) - 1000 rubles, 50 inches - 2000 rubles.
hdmi cable - goods, no attributes, price - 100 rubles.
It turns out that there must be some kind of default price, and if there is an attribute that affects the price, it will overlap it.
What happened to me:
Products table - id, price Attributes
table - id, name
Products_attributes table - id, product_id, attribute_id, attribute_value, price
In products_attributes, the price field is optional if it is filled - the price is taken from it, if not - from the products table.
1 question - is this model correct?
2 - are these tables an example of normal forms or do we need to change something, for example, put the prices of goods in a separate table?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex-1917, 2018-10-20
@Gikelan

Normally, it’s exactly the same for me)))
Only I still store the quantity along with the prices. Since the goods arrive in this way - a breakdown by options (in my case, this is the SIZE of clothes).
As for the name, there is a certain settled standard, here is how it is called in a dozen shop engines:

  • that which does not change the price is an attribute,
  • what changes the price - option
5bcb33690d45c403058537.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question