I am creating a site that is subscription based and has a complete custom checkout page. As you know, in Magento you can not have multiple recurring items in the cart at the same time which isn't an issue because people won't be allowed to sign up for multiple subscriptions. However, if once they have added one of the subscriptions to the cart they change their mind and want to choose another one, I need Magento to automatically take the other item out of the cart before adding the new one.
I added these lines of code in my addAction() function in my cart controller:
foreach ($items as $item) {
$itemId = $item->getItemId();
$cart->removeItem($itemId)->save();
$this->_getSession()->setCartWasUpdated(true);
}
So while this works, if there was something in the cart and this code runs, the $cart->save() does not save the item that was added afterwards, even though my ajax call responds that the item was successfully added and there were no errors.
Any ideas?