简体   繁体   中英

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:

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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