Magento Tips & Tricks

SUPEE 7405: Cannot remove the item from Cart

After installing SUPEE 7405 patch on client site i notice cart issue. When you add a product to the cart and trying to remove it, you got “Cannot remove the item.” error.

The issue is connected to changes in app/code/core/Mage/Checkout/controllers/CartController.php

Before

public function deleteAction()
{
    $id = (int) $this->getRequest()->getParam('id');
    if ($id) {
        try {
            $this->_getCart()->removeItem($id)
              ->save();
        } catch (Exception $e) {
            $this->_getSession()->addError($this->__('Cannot remove the item.'));
            Mage::logException($e);
        }
    }
    $this->_redirectReferer(Mage::getUrl('*/*'));
}

After

public function deleteAction()
{
    if ($this->_validateFormKey()) {
        $id = (int)$this->getRequest()->getParam('id');
        if ($id) {
            try {
                $this->_getCart()->removeItem($id)
                    ->save();
            } catch (Exception $e) {
                $this->_getSession()->addError($this->__('Cannot remove the item.'));
                Mage::logException($e);
            }
        }
    } else {
        $this->_getSession()->addError($this->__('Cannot remove the item.'));
    }

    $this->_redirectReferer(Mage::getUrl('*/*'));
}

Patch add formkey check. To fix it you need to update
[desing_package]/[theme]/template/checkout/cart/item/default.phtml

Find

<a href="<?php echo $this->getDeleteUrl() ?>" ...

Replace with

<a href="<?php echo $this->getDeleteUrl() ?>form_key/<?php echo $formKey = Mage::getSingleton('core/session')->getFormKey();?>" ...

2 thoughts on “SUPEE 7405: Cannot remove the item from Cart

    • 1. try to check that you edit correct template. you can check used templates by enabling template path hints
      2. did you clear cache after fix? try to clear it. if you are using any 3rd-party cache flush it also

Leave a Reply

Your email address will not be published. Required fields are marked *