SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Location
    UK
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Product Attributes

    Hi,

    I'm wondering if anyone could help with the following issue, as it turns out my issue is more complicated than I originally thought.

    Basically, I have come up with a small database design to allow me to store product attributes, with price changes/stock level. So I could store an attribute for a product that adds 10 to the price and has 10 stock. See below:



    However, what I'm having more of an issue with is storing combinations of attributes for stock levels. I've tried a few links tables, but everything seems to get very messyt pretty quickly. Is my original design (above)?

    Any suggestions greatly appreciated.

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by rallport View Post
    ...everything seems to get very messyt pretty quickly.
    do a search for entity-attribute-value (EAV) and you will see that many people struggle with this

    it's not you, it's the hopelessly overgeneralized design
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Here is a design you can try instead. It is rather complex but provides the ability to specify distinct pricing per physical item without being to repetitive.

    products (think of this as a abstract bucket that groups physical products ie. part numbers).
    - id
    - title

    product_part_numbers
    - id
    - products_id (product physical item belongs to)
    - sale_price
    - msrp
    - stock

    product_attributes
    - id
    - products_id (product attribute corresponds to)
    - attribute (name of attribute for products such as; color, size, weight, etc)
    - weight (ordering when product has more then a single attribute)

    product_attribute_values
    - id
    - product_attributes_id (attribute value corresponds)
    - attribute_value (value of attribute for color ie. red, blue, yellow, etc)

    product_part_numbers_to_attribute_values
    - product_part_numbers_id (physical item)
    - product_attribute_values_id (attribute value)

    Distinct pricing, stock info and attribute value combinations can now be specified per physical item (part_number).
    The only code I hate more than my own is everyone else's.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oddz, can I trouble you to explain the realtionship between the top two tables. I ain't getting it yet. (I understand the others )

    What I mean is:
    if I sell a product, it can have only one price so that would be a 1:1 relationship

    if I sell a product that comprises others (eg big mac meal has a burger, fries and drink), the relationship is still 1:1 innit?

    or is this a category : subCategory relationship?

    eg

    products
    | 1 | Menswear |

    product_part_numbers
    | 1 | Trousers |
    | 2 | Socks |

    product_attributes
    | 1 | 1 | material | 1 |

    product_attribute_values
    | 1 | 1 | Linen |

    If that is correct, I am confused as to why product_attributes is related to the products table and not, the product_part_numbers table


    bazz


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •