如何为价格更高的产品设计数据库
how to Database Design for product that have more price
我的产品有更多属性(例如颜色、尺寸,material),每个属性都有值(例如颜色有 4 个值或 material 只有 1 个值),然后产品属性的每个值都有一个价格(例如白色产品有一个价格,红色产品有一个价格)。
所以我想在 Laravel 5.5 中设计数据库,但我对此感到困惑。
一个可能的解决方案是使用 Pivot Tables 将价格存储在产品和属性本身(例如颜色)之间的 pivot/relationship
您需要实施 EAV 概念
EAV:实体属性值
您需要像这样定义数据库:
products (id, title, description) e.g. t-shirt
entities (id, title) e.g. color, size
values (id, entity_id, value) e.g. yellow, red, medium, large
entityvalues_to_products(id, product_id, entity_id, value_id) e.g. t-shirt have yellow color and could be size of large
同时在entityvalues_to_products
中添加价格属性,并在更改尺寸或颜色值时添加jquery
,它将比基本产品add/minus定价。
喜欢
- 基本产品:40 美元
- select 黄色:43 美元(加了 3 美元)
- select 大码:46 美元(再次添加 3 美元)
我的产品有更多属性(例如颜色、尺寸,material),每个属性都有值(例如颜色有 4 个值或 material 只有 1 个值),然后产品属性的每个值都有一个价格(例如白色产品有一个价格,红色产品有一个价格)。
所以我想在 Laravel 5.5 中设计数据库,但我对此感到困惑。
一个可能的解决方案是使用 Pivot Tables 将价格存储在产品和属性本身(例如颜色)之间的 pivot/relationship
您需要实施 EAV 概念
EAV:实体属性值
您需要像这样定义数据库:
products (id, title, description) e.g. t-shirt
entities (id, title) e.g. color, size
values (id, entity_id, value) e.g. yellow, red, medium, large
entityvalues_to_products(id, product_id, entity_id, value_id) e.g. t-shirt have yellow color and could be size of large
同时在entityvalues_to_products
中添加价格属性,并在更改尺寸或颜色值时添加jquery
,它将比基本产品add/minus定价。
喜欢
- 基本产品:40 美元
- select 黄色:43 美元(加了 3 美元)
- select 大码:46 美元(再次添加 3 美元)