cancel
Showing results for 
Search instead for 
Did you mean: 

Magento formKey validation not working in overrided controller

SOLVED

Magento formKey validation not working in overrided controller

I have installed Magento CE 1.9.3.1 in my local windows 7 64bit system.

Now I have overrided the `CartController` through community module as below:
magento_root\app\code\community\Company\Customcheckout\etc\config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Company_Customcheckout>
            <version>1.0.0</version>
        </Company_Customcheckout>
    </modules>
    <frontend>
        <routers>
            <Company_Customcheckout>
                <use>standard</use>
                <args>
                    <module>Company_Customcheckout</module>
                    <frontName>customcheckout</frontName>
                </args>
            </Company_Customcheckout>
        </routers>
    </frontend>
    <global>
        <routers>
            <checkout>
                <rewrite>
                    <cart>
                        <to>customcheckout/cart</to>
                        <override_actions>true</override_actions>
                        <actions>
                            <add>
                                <to>customcheckout/cart/add</to>
                            </add>
                            <index>
                                <to>customcheckout/cart/index</to>
                            </index>
                        </actions>
                    </cart>
                </rewrite>
            </checkout>
        </routers>
    </global>
</config>


magento_root\app\code\community\Company\Customcheckout\controllers\CartController.php

<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Company_Customcheckout_CartController extends Mage_Checkout_CartController {
    public function _construct() {}
    public function addAction() {
        parent::addAction();
    }
    public function indexAction() {
        parent::indexAction();
    }
}


and the app/etc/modules directory has also the relevant module's xml file.

Now when I try to add any product(from product listing page) to cart I am getting `503 Service Unavailable` error which is just title of error: `Invalid form key`. If I disable the module (i.e. disable the override) then the add to cart and redirect to cart works fine.

That makes me wonder, why it would give me `Invalid form key` error when I have just overrided the `CartController` class which has core `CartController.php` class required(path is fully correct) and I am accessing it's methods by `parent` keyword ? Firstly is it due to parent-child hierarchy of PHP ? Please provide a detailed explanation.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento formKey validation not working in overrided controller

in config.xml

<frontend>
<routers>
<checkout> <args> <modules> <Company_Customcheckout before="Mage_Checkout">Company_Customcheckout</Company_Customcheckout>
</modules>
</args>
</checkout>
</routers>
</frontend>

and the controller file

require_once Mage::getModuleDir('controllers',"Mage_Checkout").DS."CartController.php";
class Company_Customcheckout_CartController extends Mage_Checkout_CartController
{
 public function addAction(){
 //do here what you want
 }
}

 

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

View solution in original post

3 REPLIES 3

Re: Magento formKey validation not working in overrided controller

in config.xml

<frontend>
<routers>
<checkout> <args> <modules> <Company_Customcheckout before="Mage_Checkout">Company_Customcheckout</Company_Customcheckout>
</modules>
</args>
</checkout>
</routers>
</frontend>

and the controller file

require_once Mage::getModuleDir('controllers',"Mage_Checkout").DS."CartController.php";
class Company_Customcheckout_CartController extends Mage_Checkout_CartController
{
 public function addAction(){
 //do here what you want
 }
}

 

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Magento formKey validation not working in overrided controller

Hi,

Magento 1.9.3.3

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

Works for me

Re: Magento formKey validation not working in overrided controller

Kudos.!!

You saved my day.!! but i cant understand what caused the issue with slideshow.js