购物车的建模项目和选项
我正在开发一个购物车应用程序,我对如何根据以下要求对项目和选项进行建模感到非常困惑:
- 每个项目可能有零个或多个选项(颜色、尺寸等)
- 每个选项可能有几个不同的值(例如,颜色为绿色、蓝色、红色和橙色)
- 具有相同选项的两个商品可能具有不同的选项值(例如,您可以订购绿色或橙色的 T 恤,也可以订购蓝色或橙色的棒球帽)红色)
我确定这是一个有点常见的情况,但这不是我以前遇到过的情况。有什么想法吗?
I am working on a shopping cart application, and I am pretty much stumped on how to model Items and Options according to the following requirements:
- Each Item may have zero or more Options (color, size, etc)
- Each Option may have several different values (e.g. green, blue, red, and orange for color)
- Two Items with the same Option may have different values for that option (e.g. you may order a t-shirt in green or orange, and you may order a ball cap in blue or red)
I'm sure that this is a somewhat common scenario, but it is not one that I have ever faced before. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
item
表(包含项目)options
表(包含所有选项)option_value
表(存储每个选项的所有可用值)item_available_option< /code>(存储每个项目的所有可用选项)
item_available_option_value
(存储每个项目每个选项的所有可用选项值)orders
表(存储订单)order_position
表(包含订单头寸)order_pos_option
表(包含每个订单头寸的选项)这是一种非常通用的方法,允许未定义数量的选项和选项值这是基于每个项目定义的。
如果没有那么多选项,另一种选择是具体化,如下所示:
colors
表(包含所有颜色)item_available_colors
(每个 item_id 可用的颜色)sizes
表(包含所有尺寸)item_available_sizes
(每个 item_id 的可用尺寸)order_position
表(包含订单位置)item
和orders
表保持不变,所有其他表都不再需要。还有许多其他可能的变化,这旨在为您提供一个起点。
item
table (contains the items)options
table (contains all options)option_value
table (stores all available values per option)item_available_option
(stores all available options per item)item_available_option_value
(stores all available option values per item per option)orders
table (stores the orders)order_position
table (contains the order positions)order_pos_option
table (contains the options for each order position)This is quite a generic approach that allows for an undefined number of options and option value that are defined on a per item basis.
If there are not that many options, an alternative would be to go specific, something like this:
colors
table (contains all colors)item_available_colors
(available colors per item_id)sizes
table (contains all sizes)item_available_sizes
(available sizes per item_id)order_position
table (contains the order positions)The
item
andorders
tables stay the same, all others are not needed anymore.There are lots of other possible variations, this is meant to provide you with a starting point.