21278 Posts in 5728 Topics by 2599 members
General Questions
SilverStripe Forums » General Questions » Remove item from session arry does not work using Session class
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1393 Views |
-
Remove item from session arry does not work using Session class

16 August 2009 at 11:09am
So, I wanted to build my own simple SS webshop with a session shopping cart.
Getting quite far with adding and modifing quantity in the session cart.
But when I want to remove an item from the array SS keeps falling back on the old session vars. Using a regular $_SESSION does work....
The cart items array is like:
$item = array($productid => $quantity);
Example which won't work:function remove($productid){
$cart_items = Session::get('cart_items');
unset ($cart_items[$productid]);
Session::clear('cart_items'); //even this will cause SS Session to pick the old array with the rmoved item.
Session::set('cart_items', $cart_items); //this works when modifying quantity, the new array is used correct
if(!$this->isAjax()) Director::redirectBack();
}
Example which do work:function remove($productid){
$cart_items = Session::get('cart_items');
unset ($cart_items[$productid]);
$_SESSION['cart_items'] = $cart_items;
if(!$this->isAjax()) Director::redirectBack();
}
Is this a bug or am I doing something wrong? -
Re: Remove item from session arry does not work using Session class

28 August 2010 at 1:49pm
Hi,
a year later, I have the same problem. -
Re: Remove item from session arry does not work using Session class

1 September 2010 at 7:06am
Hi again,
thanks to Martijn yesterday I discovered that this was problem due to I didn't use serialize and unserialize.
| 1393 Views | ||
|
Page:
1
|
Go to Top |


