D
D
darknet372017-06-03 18:09:47
Yii
darknet37, 2017-06-03 18:09:47

How to add data to the database in a loop. Yii2?

I am making an online store. And a very big problem arose, I’ve been sitting with it for a week now and I can’t figure out how to do it. And the meaning is this: each product has a size range, each size has its own price. How can I implement all this?
I'm thinking of creating a separate table for these sizes, but how can I do this in the admin panel (which is generated via gii), I have no idea how to think it over at all.
Good people tell me what and how to do.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-06-03
@webinar

product: id | title | cost, etc.
size: id | size_name | some_size_param
product_size: id | product_id | size_id
The third link table. In the Product model, there is a relationship with Size through the product_size table.
Then, for each product, you can assign any set of sizes and there is no data duplication.
Well, or as an option, just store json with sizes directly in the product table

L
Lander, 2017-06-03
@usdglander

Push into the table with the goods another field of size and group.
That is, for each product size there will be a separate entry in the product table. Thus, by the id of the product, it will be possible to accurately determine its size. And the group - will indicate all sizes of this product.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question