I'd like to mention that I am new to the CakePHP group and this is my
first time posting. So, with that said, hello!

I am making an e-commerce site and am attempting to tackle the concept
of item options.  In my example, I have apparel related items on my
site such as shirts and shoes.  For the most part, shirts should be
listed as a single item like 'Hanes 5280 Cotton T-Shirt', but also
should have options for varying colors and sizes.  Shoes, on the other
hand might only need options for sizes. Ideally, an item could have a
matrix of colors, sizes, fabrics and any other options so I'd like to
be able to keep the number of options unlimited. No matter how many
options an item has, each unique combination of options needs to have
its own price and stock availability.  That way, for example, the
Small White shirt can cost $2 and have 10 in stock, but the Medium
White shirt costs $3 and only has 5 in stock.

I have been struggling trying to come up with the database schema and
CakePHP solution for this and wanted to know if anyone else has came
across a similar problem and wouldn't mind sharing their solution.

I have created the following table structure but I don't feel that its
correct.  The idea is that Items (i.e. Hanes 5280 Cotton T-Shirt)
hasMany ItemOptions (an ItemOption would basically be an unlimited
combination of Colors/Sizes/Etc and their stock levels) which hasMany
ItemOptionAttributes (i.e. a specific color or size name) which
belongsTo ItemOption and ItemOptionAttributeType (i.e. Size, Color,
Fabric, etc).  This is confusing as hell if you ask me but it does
seem to retrieve the correct data, although sorting that data has been
a nightmare.

There has to be a better way. I get the feeling that I'm looking at
this whole thing the wrong way and there is a much simpler solution
out there! Please help :)

--------

Here are the tables:

CREATE TABLE `items` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(64) NOT NULL ,
`short_description` VARCHAR(64) ,
`long_description` MEDIUMTEXT ,
`active` INTEGER NOT NULL DEFAULT 0,
`modified` DATETIME DEFAULT NULL,
`created` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `item_options` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`item_id` INTEGER NOT NULL ,
`price` DOUBLE ,
`stock` INTEGER NOT NULL ,
`active` INTEGER NOT NULL DEFAULT 0,
`modified` DATETIME ,
`created` DATETIME ,
PRIMARY KEY (`id`)
);

CREATE TABLE `item_option_attribute_types` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(32) NOT NULL ,
PRIMARY KEY (`id`)
);

CREATE TABLE `item_option_attributes` (
`id` INTEGER NOT NULL AUTO_INCREMENT ,
`item_option_id` INTEGER NOT NULL ,
`item_option_attribute_type_id` INTEGER NOT NULL ,
`name` VARCHAR(32) NOT NULL ,
PRIMARY KEY (`id`)
);

--------

And here are the associations:

Item hasMany ItemOption
ItemOption hasMany ItemOptionAttribute
ItemOptionAttribute belongsTo ItemOption
ItemOptionAttribute belongsTo ItemOptionAttributeType

--------

And here is a sample of the data:

Array
(
    [Item] => Array
        (
            [id] => 1
            [name] => Hanes 5280 100% Cotton T-Shirt
            [short_description] => Nice fabric. 100% Cotton! 5.6 Oz.
            [long_description] => Features: 100% cotton, 5.5 oz.;
double-needle, coverseamed neck; shoulder-to-shoulder tape.
            [active] => 1
            [modified] => 2008-05-12 10:21:54
            [created] => 2008-04-29 15:14:52
        )

    [ItemOption] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [item_id] => 1
                    [price] => 2.5
                    [stock] => 10
                    [active] => 1
                    [modified] => 2008-05-21 15:16:31
                    [created] => 2008-05-21 15:16:31
                    [ItemOptionAttribute] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 1
                                    [item_option_id] => 1
                                    [item_option_attribute_type_id] =>
1
                                    [name] => White
                                    [ItemOptionAttributeType] => Array
                                        (
                                            [id] => 1
                                            [name] => Color
                                        )

                                )

                            [1] => Array
                                (
                                    [id] => 2
                                    [item_option_id] => 1
                                    [item_option_attribute_type_id] =>
2
                                    [name] => Small
                                    [ItemOptionAttributeType] => Array
                                        (
                                            [id] => 2
                                            [name] => Size
                                        )

                                )

                        )

                )

            [1] => Array
                (
                    [id] => 2
                    [item_id] => 1
                    [price] => 3
                    [stock] => 15
                    [active] => 1
                    [modified] => 2008-05-21 15:16:44
                    [created] => 2008-05-21 15:16:44
                    [ItemOptionAttribute] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [item_option_id] => 2
                                    [item_option_attribute_type_id] =>
1
                                    [name] => White
                                    [ItemOptionAttributeType] => Array
                                        (
                                            [id] => 1
                                            [name] => Color
                                        )

                                )

                            [1] => Array
                                (
                                    [id] => 4
                                    [item_option_id] => 2
                                    [item_option_attribute_type_id] =>
2
                                    [name] => Medium
                                    [ItemOptionAttributeType] => Array
                                        (
                                            [id] => 2
                                            [name] => Size
                                        )

                                )

                        )

                )

        )

)

Thanks for looking and thanks for your time!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to