Jump to content

Recommended Posts

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.

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']

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.

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.