0

I am unable to delete the updated product from the mini cart. this is the code: path : app/code/core/Mage/Checkout/controllers/CartController.php

public function ajaxUpdateAction()
    {
        if (!$this->_validateFormKey()) {
            Mage::throwException('Invalid form key');
        }
        $id = (int)$this->getRequest()->getParam('id');
        $qty = $this->getRequest()->getParam('qty');
        $result = array();
        if ($id) {
            try {
                $cart = $this->_getCart();
                if (isset($qty)) {
                    $filter = new Zend_Filter_LocalizedToNormalized(
                        array('locale' => Mage::app()->getLocale()->getLocaleCode())
                    );
                    $qty = $filter->filter($qty);
                }

                $quoteItem = $cart->getQuote()->getItemById($id);
                if (!$quoteItem) {
                    Mage::throwException($this->__('Quote item is not found.'));
                }
                if ($qty == 0) {
                    $cart->removeItem($id);
                } else {
                    $quoteItem->setQty($qty)->save();
                }
                $this->_getCart()->save();

                $this->loadLayout();
                $result['content'] = $this->getLayout()->getBlock('minicart_content')->toHtml();

                $result['qty'] = $this->_getCart()->getSummaryQty();

                if (!$quoteItem->getHasError()) {
                    $result['message'] = $this->__('Item was updated successfully.');
                } else {
                    $result['notice'] = $quoteItem->getMessage();
                }
                $result['success'] = 1;
            } catch (Exception $e) {
                $result['success'] = 0;
                $result['error'] = $this->__('Can not save item.');
            }
        }

        $this->getResponse()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

Getting below error:

There has been an error processing your request
Invalid form key

Trace:
#0 app/code/core/Mage/Checkout/controllers/CartController.php(636): Mage::throwException('Invalid form ke...')
#1 app/code/local/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->ajaxUpdateAction()
#2 app/code/local/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('ajaxUpdate')
#3 app/code/local/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 app/code/local/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#5 app/Mage.php(684): Mage_Core_Model_App->run(Array)
#6 index.php(86): Mage::run('', 'store')
#7 {main}

What I am getting in the URL: http://example.com/checkout/cart/ajaxUpdate/id/11487/uenc/aHR0cDovL3dlYmRlbW8ubGV0c2NoYmFuZy5jby5pbi9yYXdwcmVzc2VyeS9hamF4Y2FydC9pbmRleC9hZGQvdWVuYy9hSFIwY0RvdkwzZGxZbVJsYlc4dWJHVjBjMk5vWW1GdVp5NWpieTVwYmk5eVlYZHdjbVZ6YzJWeWVTOWlkVzVrYkdWekxtaDBiV3csL3Byb2R1Y3QvODAvZm9ybV9rZXkvdkJkTUJtN3FBaHRsWDl3NS8,/

Can I know what was the problem

0

Put this into your minicart form section -

 <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
  • where should i put this code can i know the file path – prashanth Jun 14 '17 at 8:51
  • there is no form for mini cart – prashanth Jun 14 '17 at 8:55
  • is this default magento mini cart? – Soumik Rana Jun 14 '17 at 9:02
  • yes this is the default magento mini cart – prashanth Jun 14 '17 at 9:04
  • from where I mean where you fire the ajax action to pass the parameter to controller action at there also pass this form key. – Soumik Rana Jun 14 '17 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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