The idea that a commodity has a sub-commodity?

I would like to ask if there are multiple sub-items in a main commodity
multiple sub-items will have their own inventory
how can the database plan correctly?

main commodity

prod_id / stock / price
1 / 0 / 0
2 / 0 / 0
3 / 0 / 0
4 / 10 / 30

Sub-merchandise

sub_id(PK) / prod_id / stock / price
1 / 1 / 15 / 50
2 / 3 / 20 / 10
3 / 2 / 300 / 50
4 / 1 / 30 / 30
5 / 2 / 50 / 100

main merchandise 4 has no sub-merchandise, so it has its own inventory and price
1, 1, 2, and 3 all have its own sub-merchandise, so the main merchandise has no inventory and price (eyes dead

).

Shopping cart: the record of adding goods to the shopping cart (I still have who the delivery person is and I will not list the brand ID)

cart_id(PK) / prod_id / quan / price

the above shopping cart is the main item of based on.
if you add sub-items to the shopping cart, it will explode
and other databases that will explode.
and then there will be problems
.
will only display the main item. This is very simple
, but with more sub-items, I really don"t know what to do.

I revolve around the main commodity
so the main commodity plus sub-merchandise really hurts my balls.
I wonder how you have a lot of experience to deal with these problems.
what would you do if it was a big deal?

Nov.20,2021

in the field of e-commerce, the technical terms are SKU and SPU.
what you call the main commodity is a SPU. The
sub-item is SKU.

for example: an iPhone phone is a product, also known as SPU, but iPhone can have model, color, size, etc., which is SKU, inventory is one of the basic attributes of SKU.

it is obvious that SPU and SKU have an one-to-many relationship. Your watch is not designed properly. There can be no inventory and price on SPU. Move these attributes to the SKU, and then multiple SKU sets a priority for the display item.

that is, when there is more than one SKU, the first item or one of them is displayed first.

For more concepts, please refer to http://www.ikent.me/blog/3017

.

you can read this
https://codeshelper.com/a/11.


should be a product with multiple specification attributes. Spu (commodity), sku (specification). Spu+sku forms a purchasable item, and the inventory is set at

of sku.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e846da-46a9e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e846da-46a9e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?