My mini cart doesn't refresh when you try to add quantity or remove product, I have been told it needs a form key but I'm not sure what file needs to be altered the error is below:

:5:{i:0;s:16:"Invalid form key";i:1;s:893:"#0 /home/posiecou/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(604): Mage::throwException('Invalid form ke...')
#1 /home/posiecou/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->ajaxDeleteAction()
#2 /home/posiecou/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('ajaxDelete')
#3 /home/posiecou/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 /home/posiecou/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 /home/posiecou/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#6 /home/posiecou/public_html/index.php(90): Mage::run('', 'store')
#7 {main}";s:3:"url";s:91:"/checkout/cart/ajaxDelete/id/812/uenc/aHR0cDovL3d3dy5wb3NpZS5jby51ay9idXR0b25ob2xlcy5odG1s/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";
  • Which version of Magento are you using? You only need a frontend form key from 1.8CE onwards. – Jonathan Hussey Nov 10 '14 at 9:28
  • Ignore that, just noticed the 1.9 tag! – Jonathan Hussey Nov 10 '14 at 9:30
  • Do you happen to have any tracking software implemented in your site? This same issue was occurring for me, and it turned out that Adobe's Dynamic Tag Manager was what was actually causing the issue. Adobe DTM was performing a GET request on the "Remove Item" hyperlink. Our SEO team had to modify the tracking rules on their end, instructing Adobe DTM to not target that specific link. – Darren Felton Feb 10 '15 at 16:45
  • Maybe conflict with some previous installed extension? – gSorry Nov 26 '15 at 18:09

For me the problem was related to having removed the .remove class from the remove button. You either need to resolve this or change the selector in skin/frontend/<rwd>/default/js/minicart.js on line 32 to correctly target your remove button.

| improve this answer | |

I had this very same issue. In my case, the function decorateList(), inside js.js script (magento/js/varien/js.js) was trying to work with a undefined variable, which caused the javascript flow to stop because no exception was being captured. I couldn't yet find what caused this to happen but I was able to get rid of this doing the following edit to this file:

New decorateList function:

function decorateList(list, nonRecursive) {
    if ($(list)) {
        if (typeof(nonRecursive) == 'undefined') {
            var items = $(list).select('li')
        else {
                if(typeof(list) !== 'undefined') var items = $(list).childElements();
                console.log('list is undefined');
        decorateGeneric(items, ['odd', 'even', 'last']);

New decorateGeneric function:

function decorateGeneric(elements, decorateParams)
    if(typeof(elements) !== 'undefined') {
        var allSupportedParams = ['odd', 'even', 'first', 'last'];
        var _decorateParams = {};
        var total = elements.length;

        if (total) {
            // determine params called
            if (typeof(decorateParams) == 'undefined') {
                decorateParams = allSupportedParams;
            if (!decorateParams.length) {
            for (var k in allSupportedParams) {
                _decorateParams[allSupportedParams[k]] = false;
            for (var k in decorateParams) {
                _decorateParams[decorateParams[k]] = true;

            // decorate elements
            // elements[0].addClassName('first'); // will cause bug in IE (#5587)
            if (_decorateParams.first) {
                Element.addClassName(elements[0], 'first');
            if (_decorateParams.last) {
                Element.addClassName(elements[total-1], 'last');
            for (var i = 0; i < total; i++) {
                if ((i + 1) % 2 == 0) {
                    if (_decorateParams.even) {
                        Element.addClassName(elements[i], 'even');
                else {
                    if (_decorateParams.odd) {
                        Element.addClassName(elements[i], 'odd');
    console.log('elements is undefined');

This will keep the functionality working where it can work, and where it can't, it won't cause the javascript to break.

See, this is not the right way to do things in Magento because it mess with a core file.

A better solution is to do place this changes in a copy of this file and override it in your local.xml.

| improve this answer | |

The problem is for form key, The mini cart ajazDelete function is not getting form key. we can resolve the issue by removing the form key check.

Goto /app/code/core/Mage/Checkout/controllers

open the CartController.php and find the function ajaxDeleteAction()

In the function you will see

 if(!$this->_validateFormKey()) {
       Mage::throwException('Invalid form key');

Remove this line of code, and try to check the cart delete action. It will work properly now.

| improve this answer | |

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.