1

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?

1 Answer 1

1

Just figured this out. It appears the solution is to get rid of the save method after removing the item from the cart, and only have one save request on the page which should be called after all modifications to the cart are done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.