So this is a problem that I have been trying to solve for a few days now. I'm not an expert at this, but I manage quite a bit through googling and testing myself.

My website is more or less ready to go, but now one (1!) bug has halted things. I need to sort this out asap. I am currently using Magento 1.9.

The issue is easy enough to explain: When adding a product to cart, all is well. It gets added. However when removing it from the minicart I end up at the famous error page (There has been an error processing your request...). If you try to remove it from the shopping cart page (link to shopping cart page shows in the minicart when adding 3 products or more) or the checkout page (which has the same shopping cart block), that works fine.

If you want to try out the process yourself, you may go to http://bowclub.se/shop and add a product.

From the exception log I get this:

a:5:{i:0;s:16:"Invalid form key";i:1;s:970:"#0 /home/saleem80/public_html/bowclub.se/app/code/core/Mage/Checkout/controllers/CartController.php(604): Mage::throwException('Invalid form ke...')
#1 /home/saleem80/public_html/bowclub.se/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->ajaxDeleteAction()
#2 /home/saleem80/public_html/bowclub.se/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('ajaxDelete')
#3 /home/saleem80/public_html/bowclub.se/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/saleem80/public_html/bowclub.se/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 /home/saleem80/public_html/bowclub.se/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#6 /home/saleem80/public_html/bowclub.se/index.php(88): Mage::run('', 'store')
#7 {main}";s:3:"url";s:99:"/checkout/cart/ajaxDelete/id/362/uenc/aHR0cDovL2Jvd2NsdWIuc2UvZW1lcmFsZC1jcm9zcy1ib3ctdGllLmh0bWw,/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:2:"se";}

I have tried disabling all external modules, and remove anything custom that could cause the issue, but to no avail.

This is what shows up when following the process with Chrome's Console while ticking Preserve Log:

Navigated to http://bowclub.se/emerald-cross-bow-tie.html
emerald-cross-bow-tie.html:256 Uncaught ReferenceError: Minicart is not defined(anonymous function) @ emerald-cross-bow-tie.html:256x.Callbacks.c @ a59a9c78d2821cd052ee92ef84cc8cd9-1435669860.js:6088x.Callbacks.p.fireWith @ a59a9c78d2821cd052ee92ef84cc8cd9-1435669860.js:6088x.extend.ready @ a59a9c78d2821cd052ee92ef84cc8cd9-1435669860.js:6088q @ a59a9c78d2821cd052ee92ef84cc8cd9-1435669860.js:6088
2be6094b19026c6bd8648083144d17fa-1435943882.js:3 GET http://bowclub.se/checkout/cart/ajaxDelete/id/368/uenc/aHR0cDovL2Jvd2NsdWIuc2UvZW1lcmFsZC1jcm9zcy1ib3ctdGllLmh0bWw,/ 503 (Service Unavailable)e.event.special.click.setup.c.onTouchEnd @ 2be6094b19026c6bd8648083144d17fa-1435943882.js:3e.event.special.click.setup.c.handleEvent @ 2be6094b19026c6bd8648083144d17fa-1435943882.js:3
Navigated to http://bowclub.se/checkout/cart/ajaxDelete/id/368/uenc/aHR0cDovL2Jvd2NsdWIuc2UvZW1lcmFsZC1jcm9zcy1ib3ctdGllLmh0bWw,/

Please let me know if there is any more info that I can provide, and thank you for taking your time to lend me a hand!

  • Did you combine all your javascript files? Once I read that it wasn't a good idea. You can try not combine it and see if still happens this problem. – Natalie Jul 3 '15 at 20:43
  • Glad that you can solve it @Naeem – Natalie Jul 6 '15 at 14:07

You have two options,

  1. Disable form keys for the remove action.

    There is no real risk in doing this, the CSRF protection the form keys add have limited scope for damage when removed on cart actions. You could use this module as a basis if you wanted to script something

  2. Change the remove link to use

    getUrl('checkout/cart/ajaxDelete', array(..., Mage_Core_Model_Url::FORM_KEY => $this->_getSingletonModel('core/session')->getFormKey()));
    
  • Hi there, thank you for your answer! The second option seems interesting. Which file should I override for this? – Naeem Jul 3 '15 at 22:29
  • 1
    I tried the second solution in Mage_Checkout_Block_Cart_Item_Renderer, but it did not work :( – Zinat Jul 13 '16 at 6:45
  • Didn't work for me either. A fugly workaround I did is changing getAjaxDeleteUrl to getDeleteUrl in app/design/frontend/rwd/default/template/checkout/cart/minicart/default.phtml. Obviously this means a page reload and not an ajax update of the cart but this is far better than it not working at all and I don't have time for further debugging. – Klistrian Aug 24 '16 at 14:01
up vote 4 down vote accepted

Turns out that it was merging my files with the Fooman extension.

I restored my installation to a day before installing the extension and the problem is gone. Thank you Natalie for the nudge in the right direction.

What I have done instead is pretty great I think, and something I'd like to mention here for others in the future. I installed Fishpig's module Opti that minifys the js and css files, and then I installed a module by Gordon Lesti that merges the files much smarter than Magentos own method.

Please read here:

https://gordonlesti.com/projects/lestimerge/

http://fishpig.co.uk/magento/extensions/minify/

  • I also have conflict with previous installed extension, after disabling extension it works... – gSorry Nov 26 '15 at 18:08
  • You could have excluded minicart.js from the merge, that should have fixed it aswell. – loeffel Nov 17 '16 at 9:55

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

  • For me is "itemRemove: '#cart-sidebar .remove'," what should be instead? – Zinat Jul 12 '16 at 9:02
  • You don't up vote but you do get help by my answer and want more info? – Jonathan Jul 12 '16 at 9:20
  • Common, I am not sure if this is the solution to my problem even, that's why I'm asking...I'll vote if it solves – Zinat Jul 12 '16 at 9:25
  • It should match what you have in your HTML... – Jonathan Jul 12 '16 at 9:32
  • Thanks..just let you know that I have not tried your solution and I posted my question in forum – Zinat Jul 12 '16 at 10:03

Magento 1.9.3.3

Remove all code in skin/frontend/rwd/default/js/slideshow.js and refresh.

Works for me

Goto- app/code/core/Mage/Checkout/controllers/CartController.php and replace the function deleteAction() with this code.

replace this line

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

with

    $this->_goBack();

/home/88888/public_html/app/design/frontend/rwd/default/template/checkout/cart/minicart/default.phtml

remove Ajax from command line 158

            <a href="<?php echo $this->getAjaxDeleteUrl() ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Remove This Item')) ?>"

simply the line will look like this and it worked like a charm

getDeleteUrl() ?>" title="quoteEscape($this->__('Remove This Item')) ?>"

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.

  • 3
    What a terrible suggestion to simply remove the error message! – loeffel Nov 17 '16 at 8:30
  • Nether touch the core ! – Christophe Ferreboeuf Aug 9 at 8:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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