简体   繁体   English

产品数据库架构重新设计

[英]Product database schema redesign

I designed my store to sell custom machined parts. 我设计商店来出售定制的机加工零件。 Currently my products are actually a package of products (options). 目前,我的产品实际上是产品包(选件)。 Schema looks like this: 模式如下所示:

types
    id, name

products
    id, type_id, name

optiontypes
    id, name

options
    id, type_id, name

product_option
    id, product_id, option_id

carts
    id, session, product_id

cart_option
    id, cart_id, option_id

orders
    id, name

order_option
    id, order_id, option_id

My problem is Im having repeat customers that have bought packages and now want to buy single items for replacements. 我的问题是我有回头客购买了包裹,现在想购买单个物品进行更换。 I was thinking merge optiontypes into types, and options into products, but then how would I figure out whats a packaged product or a single product? 我当时在考虑将选项类型合并为类型,将选项合并为产品,但是我如何才能算出打包产品还是单个产品呢?

Edit 编辑

After reading about BOM - Modular bill of materials from pst's comment this what Im looking to do: 在阅读了BOM表-从pst的评论中了解模块化物料清单后,我打算这样做:

------------------------------------

ORDER: 1001

package1
    module1
        component1
        component2
    module2
        component3
        component4
        component5

------------------------------------

ORDER: 1002

component1
component5

------------------------------------

ORDER: 1003

package2
    module1
        component1
    module2
        component3

------------------------------------

How would I go about finding a solution to have the best of both? 我将如何寻找兼具两者的最佳解决方案?

Ok, so a package contains one or more parts . 好的,所以一个包装包含一个或多个零件 Customers can place an order for one or more packages and/or one or more parts . 客户可以订购一个或多个包装和/或一个或多个零件 Since I don't know what an option might be I more or less merged it in with *part_type* so maybe you have an Aluminum part type as well as a Pre-Drilled Aluminum part type. 由于我不知道选项是什么,所以我或多或少地将其与* part_type *合并,因此也许您具有铝制零件类型以及预钻孔的铝制零件类型。

Your order keeps track of what packages were ordered as well as what separate parts were ordered. 您的订单会跟踪订购了哪些包装以及订购了哪些单独的零件 If I'm understanding you correctly, there's no physical difference between a part that is sold as a component of a package or a part that was sold by itself - you just need to be able to track how it was purchased. 如果我正确地理解了您的意见,那么作为包装的组成部分出售的部件或单独出售的部件之间没有物理差异-您只需要能够跟踪其购买方式即可。 Setting things up like this would let you keep track of that. 像这样进行设置可以让您跟踪该情况。

packages
    id              unsigned int(P)
    description     text // This package contains all the parts you need to build SuperMegaWidget!

packages_parts
    id              unsigned int(P)
    package_id      unsigned int(F packages.id)
    part_id         unsigned int(F parts.id)

part_types
    id              unsigned int(P)
    name            varchar(50) // Aluminum, Brass, whatever, etc.

parts
    id              unsigned int(P)
    part_type_id    unsigned int(F part_types.id)
    name            varchar(50) // Widget A, Widget B, etc.

orders
    id              unsigned int(P)
    ... lots of other information in here

orders_packages
    id              unsigned int(P)
    order_id        unsigned int(F orders.id)
    package_id      unsigned int(F packages.id)

orders_parts
    id              unsigned int(P)
    order_id        unsigned int(F order.id)
    part_id         unsigned int(F parts.id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM