Shopping Cart Options theory help??

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Shopping Cart Options theory help??

Post by mischievous »

Hey guys, I am currently building a shopping cart and I am trying to wrap my head around how to add options for products...

I want the ability to to add several options to a product that will in turn generate individual skus based on option choices.

I currently have 3 tables setup in mysql:
options table
-option id
-option name

option_items table
-option id
-product id
-option 1
-option 2
-option 3

product table
-product id
-option id
-product sku
-price
..more fields that are not relative to this.

I need to have the ability to change the images, price on the product page that relates to the options picked...

I am probably not explaining this very well... so please let me know if you need more details...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Shopping Cart Options theory help??

Post by Christopher »

Can you give an example of what you mean by "options"? Is this things like size and color? It is usually best to start with SKUs and then would backward to create data to organize products for display.
(#10850)
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: Shopping Cart Options theory help??

Post by mischievous »

Ok... well, I might have figured it out... And yes, by options i mean like color, size, material or anything else that could be considered a product option....

I have setup the same three tables

:options which contains option_id, option_one, option_two, option_three;

:option_items which contains option_id, product_id, option_one, option_two, option_three;

:product which contains name, price, description, images, option_id and some other fields

I have it figured that now i can call to a product check if it has a option_id and if it does, goto the options tables, grab what options are avaliable for this product (either 1, 2, or 3) then goto the associated option_items table and search through options (1,2, or 3) with the option id specified for the product and see which sku those options are associated with?

I think it should work, although i didnt really want to limit the number of options avaliable for a product, i believe it will be easier for simplicity sake.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Shopping Cart Options theory help??

Post by Christopher »

I tend to solve the problem with SKUS, so each SKU is a unique color/size/etc. and has as its parent a product. A product is the overall name for that group of SKUs. I find the parent/child relationship easier than the link table.

:sku which contains sku, name, price, description, images, product_id and some other fields

:product which contains id, name, description, images and some other fields

The reason is that the presentation of the "product" in general is one thing -- usually when browsing categories. Whereas the presentation of each SKU is a completely different thing -- mainly done as details or selections on the "product" page.
(#10850)
Post Reply