|Different options for items depending on size|
| 7:03 pm on Jun 8, 2010 (gmt 0)|
I found the following approach in an old post here at webmasterworld for handling product options with a good deal of flexibility. I really like it; but, what happens for example if an item in size small is available only in pink but that same item in medium is offered only in blue and red?
The old thread: [webmasterworld.com ]
and the approach offered by 'rocknbil':
Taking tangor's example, I would approach this a little differently. Put manufacturers/brands in a separate table as specified.
But for "color," imagine, if you will, a widget that may have hundreds of options, and that those options can change over time. Today it's just color; suppose you want to add an option for size? And the price of the item changes with the size? Tomorrow you have a widget that has variations of color, size and say, a trim?
You have a never-ending maintenance issue of adding more tables, modifying your code, and so on.
Consider an "options table" with the following attributes:
id product_id option_id option_name option_value required price
So at any time, you may add an option:
4321 1234 345435 color red 1 0.00
4322 1234 345435 color blue 1 0.00
4323 1234 865756 color green 1 0.00
4324 1234 345534 size small 1 7.95
4325 1234 344434 size medium 1 12.95
4326 1234 343334 size large 1 14.95
4327 1234 567567 trim silver 1 0.00
4328 1234 898778 trim gold 1 0.00
4329 1234 676967 widget cover 0 5.95
So for product ID 1234, you have the following options:
required:size, with differing prices
| 3:37 pm on Jun 9, 2010 (gmt 0)|
Welcome aboard vvvvvv . . . .
|if an item in size small is available only in pink but that same item in medium is offered only in blue and red? |
One way would be to add another table for restraints. I don't have time to chase the logic ATM, but you'd have a record that only displays colors based on selected sizes. This would be difficult at best in a form, you'd have to change the available colors on change of a select list, display a table of what's available, and/or capture any discrepancies on attempted add to a cart ("That item is only available in pink for the small size.")
Another, if you have a specific set of parameters that will never change - for example, color and size will always be an option throughout all products - would be to move away from multiple tables and specify those columns in the option fields. Not anywhere near as flexible, but would be simpler to program.
| 8:01 pm on Jun 9, 2010 (gmt 0)|
Thanks for the reply!
I'm thinking on how to implement this table of restraints. Would it be a good idea to have a sort of overrides table with the following structure:
id product_id option_id option_value option2_id option2_value price
124 5687 12 small 17 pink
In this case, the item with id 5687 in size small is only available in pink.
The script would check first if there are overrides for the product_id, if there are, it fetches them, and ignores what's on the options table for the options present in the overrides table.
Thanks for your support