Magento 1.9 – Form Key Error When Removing Product from Mini Cart

form-keymagento-1.9mini-cartproduct

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!

Best Answer

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()));
    
Related Topic