Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

403 Forbidden when overriding Mage_Checkout_OnepageController
 
Andre D
Jr. Member
 
Total Posts:  13
Joined:  2008-10-29
 

I am trying to override the /checkout/onepage/saveOrder action, but after setting it up it results in a 403 Forbidden HTTP status code.

Here is what I’ve done:

<?xml version="1.0"?>
<!-- /app/code/local/Chief/Upgrade/etc/config.xml -->
<
config>
    <
modules>
        <
Chief_Upgrade>
            <
version>0.0.1</version>
        </
Chief_Upgrade>
    </
modules>
    <global>
        <
routers>
            <
checkout>
                <
rewrite>
                    <
onepage>
                        <
actions>
                            <
saveOrder>
                                <
to>upgrade/onepage/saveOrder</to>
                            </
saveOrder>
                        </
actions>
                    </
onepage>
                </
rewrite>
            </
checkout>
        </
routers>
    </global>
    <
frontend>
        <
routers>
            <
upgrade>
                <use>
standard</use>
                <
args>
                    <
module>Chief_Upgrade</module>
                    <
frontName>upgrade</frontName>
                </
args>
            </
upgrade>
        </
routers>
    </
frontend>
</
config>
// /app/code/local/Chief/Upgrade/controllers/OnepageController.php
class Chief_Upgrade_OnepageController extends Mage_Checkout_OnepageController
{
    
public function saveOrderAction()
    
{
        
// For testing, don't change behavior, just call the parent class's method
        
parent::saveOrderAction();
    
}
The saveOrder action is called by AJAX.

Does anyone know what the problem is?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

I don’t know your problem but I know that you can’t extends a controller as it’s not preloaded like model or block. This probably won’t solve your problem:

require_once "Mage/Checkout/controllers/OnepageController.php";
class 
Chief_Upgrade_OnepageController extends Mage_Checkout_OnepageController
 
Magento Community Magento Community
Magento Community
Magento Community
 
Andre D
Jr. Member
 
Total Posts:  13
Joined:  2008-10-29
 

You can extend controllers. But you’re right that extending them doesn’t work the same as extending models. Here are two articles that explain how to do it:
http://www.magentocommerce.com/wiki/how_to_overload_a_controller
http://web-magician.blogspot.com/2009/06/overriding-controllers-and-actions-in.html
In my example above I’m following the instructions in the second article, but I’ve tried both. Does anyone see any problems with what I’m doing?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Andre D
Jr. Member
 
Total Posts:  13
Joined:  2008-10-29
 

I’ve tracked the problem down to a call to

$this->getOnepage()->getQuote()->hasItems()
which returns FALSE when $this is an instance of Chief_Upgrade_OnepageController, but it returns TRUE when $this is an instance of Mage_Checkout_OnepageController. It doesn’t make sense to me because I haven’t changed any logic.

It’s as if the ‘checkout/type_onepage’ or ‘sales/quote’ objects aren’t getting loaded correctly, but I don’t think I’m doing anything here that should affect that.

Any thoughts?

 
Magento Community Magento Community
Magento Community
Magento Community
 
daria_andreani
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2010-09-06
Milan
 

Hi
any news about this?
I have the same problem.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
daria_andreani
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2010-09-06
Milan
 

Hi,

using this specific sintax to override the controller in the config.xml, has solved the problem

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

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top