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?