Topic: Facilitating Product Variants

I am building a shopping cart for my client. The client will be selling hats, t-shirts, and CDs. Two of these products have something in common: Product Variants!

I have been reading through Ben Curtis' The Money Train. He has a section on Product Variants, but it only covers 1 variant per product. T-shirts have two variants: size and color.

I know I could hard code these variations into the database and get by for now, but what happens when my client adds some other product down the road with a completely different set of variants? Sounds like a maintenance nightmare.

I remember using osCommerce and it actually let you specify any number of arbitrary 'attributes' (variants) on any product in your catalog. This would be ideal. Something like allowing my client to add a product (t-shirt), specify an attribute that varies for that product (color), and then list all of the possible choices for the variation (pink, purple, fuschia).

All of the ways I have considered accomplishing this seem overly complex. Can anyone offer some advice? Examples of DB schema, controller, or model setups would help greatly.

Last edited by jed.hurt (2006-11-11 14:00:22)

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Facilitating Product Variants

Here is my first try at a schema and some model declarations. I am just wondering how I could create line_items with this schema. Could it be further simplified?

http://img233.imageshack.us/img233/2450/picture2zu6.png

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Facilitating Product Variants

line_items would also have to be linked to attributes/variations. I'd write something like a line_item_attributes model that stores line_item_id, attribute_id, and variation_id for the chosen variation. Write a new record for each different product attribute associated with a line item.

vinnie - rails forum admin