Jump to content

Transferring Sizes Into My Shopping Cart


Hilly_2004

Recommended Posts

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...

[a href=\"http://img96.imageshack.us/my.php?image=checkout14eq.jpg\" target=\"_blank\"][img src=\"http://img96.imageshack.us/img96/6223/checkout14eq.th.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]

However now I want to transfer [b]sizes[/b] 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...

[code]
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;
}
[/code]

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...

[a href=\"http://img96.imageshack.us/my.php?image=checkout20xd.jpg\" target=\"_blank\"][img src=\"http://img96.imageshack.us/img96/7765/checkout20xd.th.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]

...firstly I need to change that and then I need to figure out a way of creating it so that it looks like this:

[a href=\"http://img96.imageshack.us/my.php?image=checkout35si.jpg\" target=\"_blank\"][img src=\"http://img96.imageshack.us/img96/9720/checkout35si.th.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]

My checkout code looks like this:

[code]
    $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']));
[/code]

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.
Link to comment
Share on other sites

you will have to add another element to your 'cart' array to store the new data. You may also have to add to the script that displays the cart info so that it too displays the new information.

You have the code in place to insert new elements to the array so just use that and make sure the data is passed from the form correctly.
Link to comment
Share on other sites

So do you suggest adding something like this after...

if($HTTP_SESSION_VARS['cart'][$i]['Item_ID'] == $itemID)


&& ($HTTP_SESSION_VARS['cart'][$i]['Size'] == $size) {

However that won't validate will it, so how can I get an extra field into the cart session?
Link to comment
Share on other sites

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.