Question

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!

Was it helpful?

Solution 2

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/

OTHER TIPS

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

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.

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')) ?>"

Background:

I had issue in Magento 2. I found out form_key was coming null in parms. Due to which below condition in execute() method

if (!$this->getFormKeyValidator()->validate($this->getRequest())) {
            return $this->resultRedirectFactory->create()->setPath('*/cart/');
        }

stops action of removing item from mini cart dropdown.

I also noticed form_key was part of cookies. The only problem was it was not getting sent as Form Data.

Solution:

I solved it by creating before plugin for execute() method of class Magento\Checkout\Controller\Sidebar\RemoveItem

In plugin, I got form_key from cookies and setted it in param and BOOM

use Magento\Framework\App\RequestInterface;

class RemoveItem
{
    protected $_request;

    public function __construct(RequestInterface $request)
    {
        $this->_request = $request;
    }

    public function beforeExecute(
        \Magento\Checkout\Controller\Sidebar\RemoveItem $subject
    ):array
    {
        if (!$this->_request->getParam('form_key')) {
            $formKey = $this->_request->getCookie('form_key', null);
            $this->_request->setParams(['form_key'=>$formKey]);
        }
        return [];
    }
}

Hope it will be helpful for future readers.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top