ShaunTheSheep
ShaunTheSheep

Reputation: 281

Magento controller override

I am trying to overwrite a controller of an extension....that is overwriting the cart controller.

The extension currently overwriting the cart controller is:

Innoexts/Warehouse/controllers/Checkout/CartController.php

The config entry in the Innoexts module doing this is:

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

...blah...blah...

</frontend>

The top of the innoext cartcontroller file is:

require_once 'Mage/Checkout/controllers/CartController.php';
class Innoexts_Warehouse_Checkout_CartController extends Mage_Checkout_CartController {

I want to overwrite it with this controller:

Myco/Warehousemod/controllers/Checkout/CartController.php

The top of the controller file is:

require_once 'Innoexts/Warehouse/controllers/Checkout/CartController.php';
class Myco_Warehousemod_Checkout_CartController extends Innoexts_Warehouse_Checkout_CartController {

The config entry ive created is:

<global>

...blah...blah...

<rewrite>
        <myco_warehousemod_checkout_cart>
            <from><![CDATA[#^/checkout/cart/#]]></from>
            <to>/warehousemod/checkout_cart/</to>
        </myco_warehousemod_checkout_cart>
    </rewrite>

</global>


<frontend>

<routers>
        <checkout>
    <args>
        <modules>
                  <Myco_Warehousemod before="Innoexts_Warehouse_Checkout">Myco_Warehousemod_Checkout</Myco_Warehousemod>
                </modules>
            </args>
        </checkout>
    </routers>

...blah...blah...

</frontend>

I am getting a 404 not found error for the checkout/cart URL now....Can anyone see where im going wrong? Online resources are very different...and confusing!! The issue may be with me trying to overwrite an overwriting controller...??

thanks in advance...

Upvotes: 0

Views: 3174

Answers (4)

Dilhan Maduranga
Dilhan Maduranga

Reputation: 2281

This is a little notification on the include path of the controller.

This include path can cause errors if the Magento Compiler mode is turned on.

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

Instead of that it is good to use

require_once Mage::getModuleDir('controllers', 'Mage_Checkout').DS.'CartController.php';

It will be safer.

Upvotes: 0

Emi
Emi

Reputation: 1018

This part was used in the old versions of Magento (i think before 1.4), but if you want to extend a controller that has a rewrite like this in the config file, you have to do the same in your config.

<rewrite>
    <myco_warehousemod_checkout_cart>
        <from><![CDATA[#^/checkout/cart/#]]></from>
        <to>/warehousemod/checkout_cart/</to>
    </myco_warehousemod_checkout_cart>
</rewrite>

The new versions use only the part with before so you should have something like this:

<routers>
  <checkout>
    <args>
        <modules>
           <Myco_Warehousemod before="Innoexts_Warehouse">Myco_Warehousemod_Checkout</Myco_Warehousemod><!-- just the name of the module Innoexts_Warehouse the overridden folder will be taken from the part after the name of your module so Magento will look in app/local/Myco/Warehousemod/controllers/Checkout/* and load all the controllers from there -->
        </modules>
    </args>
  </checkout>
</routers>

Upvotes: 1

ShaunTheSheep
ShaunTheSheep

Reputation: 281

Need to remove the first rewrite:

<rewrite>
    <myco_warehousemod_checkout_cart>
        <from><![CDATA[#^/checkout/cart/#]]></from>
        <to>/warehousemod/checkout_cart/</to>
    </myco_warehousemod_checkout_cart>
</rewrite>

I think certain people should stop writing tutorials....cluttering up the web with their half-assed SEO efforts....

Upvotes: 1

Related Questions