Jump to content


Photo

Transferring Sizes Into My Shopping Cart


  • Please log in to reply
7 replies to this topic

#1 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 06 April 2006 - 02:16 AM

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

[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:

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


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.

#2 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 06 April 2006 - 11:45 PM

*Bump before it goes off the page*

#3 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 April 2006 - 02:41 AM

[img src=\"http://www.phpfreaks.com/forums/style_images/1/folder_post_icons/icon9.gif\" border=\"0\" alt=\"IPB Image\" /]

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 April 2006 - 03:02 AM

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.
follow me on twitter @PHPsycho

#5 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 April 2006 - 02:26 PM

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?


#6 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 10 April 2006 - 12:51 PM

[img src=\"http://www.phpfreaks.com/forums/style_images/1/folder_post_icons/icon9.gif\" border=\"0\" alt=\"IPB Image\" /]


#7 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 10 April 2006 - 11:28 PM

lol...Im going to keep bumping until some sod replies lol :)

#8 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 13 April 2006 - 01:10 AM

*Sigh* Please? Anyone? Getting desperate now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users