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

Controller Overwrite Issue
 
xmrcivicboix
Jr. Member
 
Total Posts:  22
Joined:  2009-07-16
 

I have this weird problem and I’m having a hard time location answers so I was wondering if anyone could help. Basically, I extended the CartController so I can render an html fragment via ajax. However, it breaks my other controllers. For instance, I get a 404 for /checkout/onepage but /checkout/cart is fine. Here is my code:

controllers/CartController.php

<?php

require_once 'Mage/Checkout/controllers/CartController.php';

class 
Namespace_Checkout_CartController extends Mage_Checkout_CartController
{
    
public function viewAjaxAction()
    
{
        $this
->loadLayout();
        echo 
$this->getLayout()->createBlock('Namespace_Checkout_Block_Cart_Ajax')->renderView();
        return;
    
}
}

etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Namespace_Checkout>
            <
version>0.1.0</version>
        </
Namespace_Checkout>
    </
modules>
    <
frontend>
        <
routers>
            <
checkout>
                <use>
standard</use>
                <
args>
                    <
module>Namespace_Checkout</module>
                    <
frontName>checkout</frontName>
                </
args>
            </
checkout>
        </
routers>
    </
frontend>
    <global>
        <
blocks>
            <
account>
                <class>
Namespace_Checkout_Block</class>
            </
account>
        </
blocks>
    </global>
</
config>

<?xml version="1.0"?>
<config>
    <
modules>
        <
Namespace_Checkout>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Namespace_Checkout>
    </
modules>
</
config>

What am I doing wrong here? I also extended a Customer_AccountController and same thing happen. Anythoughts?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
GKOVACS
Jr. Member
 
Total Posts:  15
Joined:  2009-07-29
 

You have to add the rewrite tag.

See this: http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/

 
Magento Community Magento Community
Magento Community
Magento Community
 
xmrcivicboix
Jr. Member
 
Total Posts:  22
Joined:  2009-07-16
 

I already have it working correctly but other controllers are giving me a 404 is what I’m referring to. The link above is great but not help in solving my problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
magedev
Sr. Member
 
Avatar
Total Posts:  117
Joined:  2009-06-01
 

Up to version 1.3.0 you can use this method of overriding controller. From version 1.3.0 there’s a way to assign multiple controllers to single route (see Lee Saferite posts)

 
Magento Community Magento Community
Magento Community
Magento Community
 
xmrcivicboix
Jr. Member
 
Total Posts:  22
Joined:  2009-07-16
 

Guys, everything is working fine like I mentioned. But what I’m saying is that it causes the OnepageController to throw a 404. I’m not sure if naming my module same as Magento core has any affect or not. Here is my directory layout:

local
----IMedia
--------Checkout
------------Block
----------------Cart
----------------Ajax.php
------------controllers
----------------CartController.php
------------etc
----------------config.xml

I’m almost positive that Magento is looking in IMedia/Checkout/controllers/ for the OnepageController.php which doesn’t exists. For goodness’s sake, I created a OnepageController.php in my namespace and it worked.

<?php

require_once 'Mage/Checkout/controllers/OnepageController.php';

class 
IMedia_Checkout_OnepageController extends Mage_Checkout_OnepageController
{

}

Is there a way that I don’t have to do this in order for Magento to recognize this? I tried renaming my module but that didn’t work.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

See this post:  http://www.magentocommerce.com/boards/viewthread/37244/P15/#t161416

Instead of overriding the OnepageController, just override the CartController.

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