PDA

View Full Version : Shopping cart items


Kal
01-15-2007, 12:48 PM
guys im trying to fix a couple of bugs in my shopping cart application, basically when you add a product into the cart and hit refresh the same product gets added again depending on how many times you refresh.

i have the following code but getting erros on the highlighted lines.

any help would be great.

switch ($action)

{

case 'add':

$last_add = $session->get('last');
if (!$last_add)

{

if ($cart)
{
$cart .= ','.$_GET['product_id'];
}

else
{
$cart = $_GET['product_id'];
}
}

else

{

$last_arr = explode('|',$last_add);
$last_item = $last_arr[0];
$last_time = $last_arr[1];

if ($product_id == $last_item && ($last_time - time() < 300))

{
}

else

{

if ($cart)
{
$cart .= ','.$_GET['product_id'];
}
else
{
$cart = $_GET['product_id'];
}

}

}

$session=>set('last',$product_id.'|'.time());
break;

Fumigator
01-15-2007, 10:56 PM
What errors?

Kal
01-16-2007, 09:49 AM
sorry the following lines

$last_add = $session->get('last');

$session=>set('last',$product_id.'|'.time());

i get a Call to a member function on a non-object error

i dont think that the product_id and time of the last added item is being stored in the session variable last and not being called correctly.

Fumigator
01-16-2007, 08:31 PM
The error is, $session is not an object. You have to instantiate the object before you can refer to it.

Kal
01-17-2007, 08:42 AM
how do i go about doing that?