adrian28uk Posted January 20, 2008 Share Posted January 20, 2008 I am building a small shopping cart to see how far my php knowledge can take me. I was wondering what is the best way to implement product options on the products. For example I might be selling T-Shirts, and they might be available in 3 colours. Red (+ £3.00) Black (+ £2.50) Yellow (+ £0.00) I'm not looking for any code, I would like to know how you would plan this, and if you have done this before, and how you do it. Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/ Share on other sites More sharing options...
Northern Flame Posted January 20, 2008 Share Posted January 20, 2008 well u can have a set value for the product. then have a <select></select> thing with like this: <select name="color"> <option value="3.00">red</option> <option value="2.50">black</option> <option value="0.00">yellow</option> </select> then in your php script get the product value and add it with $_POST['color'] Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444148 Share on other sites More sharing options...
Bauer418 Posted January 20, 2008 Share Posted January 20, 2008 well u can have a set value for the product. then have a <select></select> thing with like this: <select name="color"> <option value="3.00">red</option> <option value="2.50">black</option> <option value="0.00">yellow</option> </select> then in your php script get the product value and add it with $_POST['color'] Too much work required just to verify the user's input because a fake value can be inserted easily. I'd go more for this approach: <select name="product_variant"> <option value="1">red</option> <option value="2">black</option> <option value="3">yellow</option> </select> Then you'd have another table in your database called product_variant (which has a column product_id to relate each variant to a particular id) and then you can get the price out of your product variant table. Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444150 Share on other sites More sharing options...
Northern Flame Posted January 20, 2008 Share Posted January 20, 2008 Too much work required just to verify the user's input because a fake value can be inserted easily. yea thats true, it could easily be faked using the method I posted.... Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444156 Share on other sites More sharing options...
adrian28uk Posted January 20, 2008 Author Share Posted January 20, 2008 I see. So the id is inserted in to the database. Then when calling the cart you can access the id which in turn brings up the product option name and price you selected. Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444161 Share on other sites More sharing options...
Northern Flame Posted January 20, 2008 Share Posted January 20, 2008 you dont necessarily need to use a database. you could just do this: <?php switch($_POST['color']){ case 1: $add = 3; break; case 2: $add = 2.50; break; case 3: $add = 0; break; } then do your product value + $add to get final price Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444177 Share on other sites More sharing options...
Bauer418 Posted January 20, 2008 Share Posted January 20, 2008 you dont necessarily need to use a database. you could just do this: <?php switch($_POST['color']){ case 1: $add = 3; break; case 2: $add = 2.50; break; case 3: $add = 0; break; } then do your product value + $add to get final price Yes, but could you imagine having to do that kind of code for every single product on your website. Very inefficient. Link to comment https://forums.phpfreaks.com/topic/86877-shopping-cart-implementing-product-options/#findComment-444323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.