Hi guys,
I really need your help because I am truly stumped. At the minute I have your basic shopping cart, items are added up and if you add multiple items it changes the quantity field to match and it looks like so...
http://img96.imageshack.us/my.php?image=checkout14eq.jpg
However now I want to transfer sizes into the checkout as well, I already have the form set up when you browse the item and it transfers a variable called $Size (containing values like 'Small', 'Medium' etc...) to the lib file where all the information submitted is then transformed into information for the checkout...
if(!isset($HTTP_SESSION_VARS['cart'])){
$HTTP_SESSION_VARS['cart']=array();
$HTTP_SESSION_VARS['items']=0;
$HTTP_SESSION_VARS['total']="0.00";
}
if($add){
$itemID = $HTTP_POST_VARS['product'];
$isFound = false;
for($i =0; $i< count($HTTP_SESSION_VARS['cart']); $i++){
if($HTTP_SESSION_VARS['cart'][$i]['Item_ID'] == $itemID){
$isFound = $i;
break;
}
}
if($isFound !== false){
$HTTP_SESSION_VARS['cart'][$isFound]['quantity']++;
}else{
$newItem = array();
$newItem['Item_ID'] = $itemID;
$newItem['quantity'] = 1;
array_push($HTTP_SESSION_VARS['cart'], $newItem);
}
$HTTP_SESSION_VARS['items']++;
// array_push($HTTP_SESSION_VARS['cart'], $product);
$HTTP_SESSION_VARS['total']+=$price;
}
However the way my cart is set up is that it doesn't show the multiple items of the same type seperately instead it puts a 2 in the quantity field...
http://img96.imageshack.us/my.php?image=checkout20xd.jpg
...firstly I need to change that and then I need to figure out a way of creating it so that it looks like this:
http://img96.imageshack.us/my.php?image=checkout35si.jpg
My checkout code looks like this:
$subtotal = 0;
for($i=0; $i<count($myCart); $i++){
$query="SELECT * FROM Items WHERE Item_ID = '".$myCart[$i]['Item_ID']."'";
$result=mysql_query($query, $conn);
$basketItems=mysql_fetch_array($result);
$subtotal+=($basketItems['UK_Price']*$myCart[$i]['quantity']);
//ITEM NAME
echo $basketItems['Item_Name'];
//QUANTITY
echo $myCart[$i]['quantity'];
//PRICE (exc VAT)
echo money_format($fmt, ($basketItems['UK_Price']*$myCart[$i]['quantity']));
The form to add the items to the basket looks like this...
<form action="browse_items.php?ItemID=<?php echo $product['Item_ID'];?>" method="post">
$result = mysql_query("SELECT * FROM Sizes WHERE Item_ID ='$ItemID' ");
while($myrow = mysql_fetch_assoc($result))
if ($myrow['Item_Quantity'] == 0)
{
echo '<select name="Size" size="1">';
if ($myrow['YS_Quantity'] > 0) {
echo "<option selected value=\"Youth Small\">Youth Small</option>";
}
if ($myrow['YM_Quantity'] > 0) {
echo "<option value=\"Youth Medium\">Youth Medium</option>";
}
if ($myrow['YL_Quantity'] > 0) {
echo "<option value=\"Youth Large\">Youth Large</option>";
}
if ($myrow['YXL_Quantity'] > 0) {
echo "<option value=\"Youth Extra Large\">Youth Extra Large</option>";
}
if ($myrow['Small_Quantity'] > 0) {
echo "<option selected value=\"Small\">Small</option>";
}
if ($myrow['Medium_Quantity'] > 0) {
echo "<option value=\"Medium\">Medium</option>";
}
if ($myrow['Large_Quantity'] > 0) {
echo "<option value=\"Large\">Large</option>";
}
if ($myrow['Xlarge_Quantity'] > 0) {
echo "<option value=\"Extra Large\">Extra Large</option>";
}
if ($myrow['XXlarge_Quantity'] > 0) {
echo "<option value=\"Extra Extra Large\">Extra Extra Large</option>";
}
echo '</select>';
}
<input type="image" value="SUBMIT" alt ="Add To Cart" src="images/addtocart.png">
<input type="hidden" name="add" value="1">
<input type="hidden" name="product" value="<?php echo $product['Item_ID'];?>">
<input type="hidden" name="price" value="<?php echo $product['UK_Price'];?>">
<input type="hidden" name="name" value="<?php echo $product['Item_Name'];?>">
</form>
This is quite a long winded request, but as much or as little help would be great. Any further information then please just ask.
P.S. Some of the details on the screenshots are wrong, but you get the jist from the explanations.