I am creating a fairly simple online store in SilverStripe. I am writing a function to remove an item from the recycle bin ( order in my case).
My setup:
My endpoint returns JSON in a view for use in ajax.
public function remove() { // Get existing order from SESSION $sessionOrder = Session::get('order'); // Get the product id from POST $productId = $_POST['product']; // Remove the product from order object unset($sessionOrder[$productId]); // Set the order session value to the updated order Session::set('order', $sessionOrder); // Save the session (don't think this is needed, but thought I would try) Session::save(); // Return object to view return json_encode(Session::get('order')); }
My problem:
When I send data to this route, the product is deleted, but only temporarily, then called the next time, the previous item is returned.
Example:
Property order:
{ product-1: { name: 'Product One' }, product-2: { name: 'Product Two' } }
When I send a message to remove product-1 , I get the following:
{ product-2: { name: 'Product Two' } }
Which seems to have worked, but then I will try to remove product-2 and get the following:
{ product-1: { name: 'Product One' } }
SON AB is back! When I remove the entire basket, it still contains both.
How do I get order to stick?
source share