mysql best way to manage product sizes

做~自己de王妃 提交于 2019-12-06 00:10:00

It seems like you're forcing 'clothing size', 'weight' and 'length' into one 'size' attribute.

Try these tables:

  product (product_id, name)
    "Nike t-shirt"

  attribute_group (attribute_group_id, name)
    "Shirt size", "Weight", "Length", etc.

  attribute_value (attribute_value_id, attribute_group_id, name)
    "Shirt size" would have rows for "Small", "Large", etc.

  product_attribute (product_id, attribute_value)
     "Nike t-shirt" is "Large"

Add a "display order" to attribute_value, too (so "Small" can be displayed before "Large").

Do this for your other attributes, too.

I've done this for a production site, and I think it worked well.

Good luck.

Instead of making a seperate table for this, why don't you just put all of your dropdown options in an application scoped variable? Then you can just add that data right into a field in product as a string and deal with the different options/units programmatically.

I made a database storing clothes where the sizes were a few types.One article has sizes like xs s m l other is 26 27 28 29 30 and so on. I decided to do this:

# on one side in the script i define size types and names;
$sizeTypes[1] = [XS, S, M, L];
$sizeTypes[2] = [29, 30, 31, 32];
#The and so on
#and on the other side in the database, there are just two columns

size_type_id(int) | size_qty |

# so if I have one article with 3 pieces of size S 2 pieces of size M and 5 pieces of size L the database will store:
size_type_id|  size_qty     |
1           |0:0;1:3;2:2;3:5|

then in the script I just translate it so that 0 of type 1 is XS 1 of type 1 is S 2 of type 2 is 31 and so on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!