购物车订购表
我正在开发在线购物车系统。现在我需要将商品/购物篮添加到订单表中。我想确定我是否走在正确的道路上?
以下是主要产品表:
items table
- item_id (p)
- item_name
- item_description
注意:商品价格位于 item_options 表
item_options table
- option_id (p)
- item_id (f)
- option_name
- option_price 中
item_extras 表
- extras_id (p)
- option_id (f)
- extras_name
- extras_price
下面是订单表。正如您可以看到的商品名称、选项名称和附加名称,价格将复制到订单表中。如果任何商品名称或价格发生变化 - 不会影响订单表。例如,发票不会受到影响。
订单表
- orders_id(p)
- f)
- address_book_id(f)(用于送货地址)
- date_purchasedorders_statusorders_date_finished
- orders_items_id
- customer_id (
order_items表
- (p)
- orders_id(f)
- item_id(f)
- item_name(从项目表复制)
- item_description(从项目表复制)
- option_id (f)
- option_name (从 item_options 表复制)
- option_price (从 item_options 表复制)
order_extras 表
- order_extras_id (p)
- orders_id(f)
- orders_items_id(f)
- extras_id(f)
- extra_name
- extra_price
I am developing online Shopping Cart system. Now I need to work on adding the items/basket into order tables. I wanted to make sure if I'm going on the right path?
These are the main products tables:
items table
- item_id (p)
- item_name
- item_description
Note: item prices are in the item_options tables
item_options table
- option_id (p)
- item_id (f)
- option_name
- option_price
item_extras table
- extras_id (p)
- option_id (f)
- extras_name
- extras_price
Below are the orders tables. As you can see the item name, option name and extras name, prices are copied into orders tables. If any of item name or prices changed - it will not affect the order tables. For example the invoices will not be affected.
orders table
- orders_id (p)
- customer_id (f)
- address_book_id (f) (for delivery adddress)
- date_purchased
- orders_status
- orders_date_finished
order_items table
- orders_items_id (p)
- orders_id (f)
- item_id (f)
- item_name (copied from items table)
- item_description (copied from items table)
- option_id (f)
- option_name (copied from item_options table)
- option_price (copied from item_options table)
order_extras table
- order_extras_id (p)
- orders_id (f)
- orders_items_id (f)
- extras_id (f)
- extra_name
- extra_price
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想对此数据库模式提出两个潜在的优化。
首先,是否有任何附加功能可以应用于两个不同的选项,例如选项和附加功能具有多对多关系?如果是这样,您需要添加具有以下结构的链接表:
然后通过删除 optionId 字段来更改 extras 表。这可以消除潜在的冗余。
其次,与其重复项目名称、选项名称和额外名称,为什么不在每个标题为“活动”的表中添加一个布尔值(0-1)行,这表示每个表中的哪些条目当前可以在订购时选择。这样可以避免额外的冗余,并且可以重新安装产品,而不会对旧发票上的信息产生任何影响。当您想要更改产品的价格或名称时,只需关闭当前活动记录,然后插入包含新信息的新记录即可。旧订单显然仍然指向不活动条目的正确 ID。
您还可以更进一步,使用活动列来表示输入特殊代码的人可以使用的产品,例如将这些产品标记为活动 = 2。
无论如何,这些是我的想法,希望它们对您有所帮助!
I'd like to raise two potential optimisations to this database schema.
Firstly, are there any extras which could apply to two different options e.g. options and extras has a many-to-many relationship? If so you need to add a link table with the following structure:
you then alter the extras table by removing the optionId field. This could remove potential redundancy.
Secondly, instead of duplicating item names, option names and extra names why not add a boolean(0-1) row into each table titled active which signifies which entries in each table are currently possible to be selected at the time of ordering. This way the extra redundancy is avoided and products can be re-instated, without any effect on information on old invoices. When you want to change the price or name of a product you just turn the current active record to off and then insert a new record with the new information. The old orders obviously still point the correct id of the entry that is not active.
You could also take this one step further and use the active column to signify products which are available to people that type in special codes e.g. label these products active = 2.
Anyway, those are my thoughts, hope they are helpful!