Hi all,
Just trying to work out if I was to build my own
Online store, how I would have a product but it will have
Different sizes and each size is a different price.
Just can’t figure out how to do this in my head
Hi all,
Just trying to work out if I was to build my own
Online store, how I would have a product but it will have
Different sizes and each size is a different price.
Just can’t figure out how to do this in my head
If all your products have sizes you could have a sub reference table that holds the product ID, sizes and prices. So your product table would hold all the info that is common to a range and the size table would hold the info specific to the size.
However if most items don’t have sizes at all, Id be inclinded to repeat each item in the database under a seperate product ID
Give us a clue as to what your selling
Hey dude, sorry for the delay in the reply, only managed to get to my computer. It’s for a camera shop, the bulk of what we sell does not require any attributes at all, however filters for example have different thread sizes and each needs a different price. It would look messy to set up a product for each size. I’m hoping to have a drop-down list of sizes and it’s price.
OK, then in your product table you have a field called ‘sized’, default set to false. If your item is sized then you set this value to true.
Your size table would consist of
Size_ID (Unique auto increment)
Prod_ID (to link the table to your products table)
Size
on the display side if ‘sized’ is true the sizes are displayed from the sizes table. (you could equallly do away with the ‘sized’ field and just search through the sizes table to see if the product exists in that table)
To do it properly the prices should be seperated into another table too, its bad database design to have the same info in two different places. Your prices table would look like
Price_ID (unique auto inc)
Prod_ID
Size_ID (default to Zero)
Price
NOw for any prod ID you can see if they are sizes available if so the price is found by looking for the pair of Prod_ID and Size_ID, if no size is available you search for price on Prod_ID and Size=zero.
Hi Mandes, thanks for the reply. That’s exactly what I was looking for, just couldn’t work out the logic behind it. I guess I would then just need to use a join on the two tables and then add the selected price to the session (shopping cart).
you got it