Magento: what does option "before" do in config.xml file? - magento

I added admin controller.
This code works correct:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<mycompany_mymodule>Mycompany_Mymodule_Adminhtml</mycompany_mymodule >
</modules>
</args>
</adminhtml>
</routers>
</admin>
If I add before="Mage_Adminhtml" to mycompany_mymodule:
<mycompany_mymodule before="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</mycompany_mymodule >
then it doesn't work - got 404 error.
1. What does this option do?
Also I looked throught Alans' Storm article: http://alanstorm.com/magento_admin_controllers
There are example:
<config>
<!-- ... -->
<admin>
<routers>
<the_name_of_this_element_is_not_important_it_should_be_unique>
<use>admin</use>
<args>
<module>Alanstormdotcom_Adminhelloworld</module>
<frontName>adminhelloworld</frontName>
</args>
</the_name_of_this_element_is_not_important_it_should_be_unique>
</routers>
</admin>
<!-- ... -->
</config>
2. What is the difference between these definitions?

It solved:
I found Mage_Core_Controller_Varien_Router_Standard class where collectRoutes() method is defined. It parses "after" and "before" parameters to order the modules.
This method is calling from Mage_Core_Controller_Varien_Router_Admin (started from init method in Mage_Core_Controller_Varien_Front).
So after I looked through match process in Mage_Core_Controller_Varien_Router_Standard.
After Mage_Core_Controller_Varien_Router_Standard debuging I understood my fault.
I used Index controller instead of MyModuleContoller.
Alan Storm defined controller which is not under the admin module (i.e. adminhtml). When I use first config - it works perfect because I defined new modules under the section adminhtml. In Alan's config I cannot add my module to adminhtml. I could override it but it is not correct because other modules under the adminhtml will be removed then.
This is correct code for menu under the adminhtml:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<mycompany_mymodule after="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</mycompany_mymodule >
</modules>
</args>
</adminhtml>
</routers>
</admin>
Inchoo also described this config here.

Related

how to resolve front router conflict when two module with same name in diff namespace

i have same situation with this question (same module name with different namespace conflicting in magento )
but my problem is how to solve the front controler conflict.i don't want to rewrite the other module but still want to keep the same module name.
ie:the module name is moduleabc,so the url would be
moduleabc/controller/action/
<routers>
<moduleabc>
<use>standard</use>
<args>
<module>A_moduleabc</module>
<frontName>moduleabc</frontName>
</args>
</moduleabc>
</routers>
i have tried to edit config.xml as below
<routers>
<moduleabc>
<use>standard</use>
<args>
<module>B_moduleabc</module>
<frontName>moduleabc</frontName>
</args>
</moduleabc>
</routers>
and i found that when magento try to instantiate source model for adminhtml,ie.
moduleabc/source_trans
will be parsed to
A_Moduleabc_Source_Trans class
THE CONFIG.XML for both:
<global>
<models>
<moduleabc>
<class>A_Moduleabc_Model</class>
<resourceModel>Moduleabc_mysql4</resourceModel>
</moduleabc>
<global>
<models>
<moduleabc>
<class>B_Moduleabc_Model</class>
<resourceModel>Moduleabc_mysql4</resourceModel>
</moduleabc>
you can change the <frontName>moduleabc</frontName> with some other and on frontend you can access your module with new frontname. thanks

Generate Magento URL with secret key (nonce)

I am trying to implement Selenium testing for Magento installation.
I stack at very beginning when I need to open specific URL in the Admin Section for Custom Module. Magento nonce is on and this parameter can not be changed.
To keep this more simple, I just need a URL like this:
http://mag.local/index.php/mymodule/mycontroller/index/key/e9310760d8bb9451e41e21105a87e874/
With following code I can receive
mag.local/mymodule/mycontroller/index/key/another_nonce/, which as you can imagine does not work.
$url = Mage::helper("adminhtml")->getUrl('mymodule/mycontroller/index');
My config:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<mymodule_mycontroller before="Mage_Adminhtml">Mymodule_Mycontroller</mymodule_mycontroller>
</modules>
</args>
</adminhtml>
<mycontroller_route>
<use>admin</use>
<args>
<module>Mymodule_Mycontroller</module>
<frontName>mycontroller</frontName>
</args>
</mycontroller_route>
</routers>
</admin>
Mage::getModel('adminhtml/url')->getUrl('route/path/here', array('another' => 'route_param'));
This should generate the super secret route parameter.
Reference: http://alanstorm.com/magento_admin_hello_world_revisited

Magento Currency Symbol 404's when i go to admin

Any ideas what would cause:
admin->system->manage currency->symbols
to 404 when i go to it in the admin?
admin->system->manage currency->rates (works fine).
This is on my mamp local.
i guess i'm asking is there a 'troubleshooting' way to find out why it's 404'ing for any module in the admin?
I had the same problem - though I do not know whether it is caused by any extensions. Somehow not many people seem to have encountered this problem yet.
Change line 68 in app\code\core\Mage\CurrencySymbol\etc\config.xml: and
change From
<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
to
<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>
Go to line 68 in app/code/core/Mage/CurrencySymbol/etc/config.xml
<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
Replace to
<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>
Go to line 34 in app/etc/modules/Mage_CurrencySymbol.xml add the Mage_Adminhtml tag
<depends>
<Mage_Adminhtml />
<Mage_Widget/>
</depends>
The error occurs with the definition of the admin router. It appears not only to be a windows error as I am also getting this on a linux machine. Currently it looks as follows:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
</modules>
</args>
</adminhtml>
</routers>
</admin>
But if you use the "before" tag and specify "Mage_Adminhtml" then it will work.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>
</modules>
</args>
</adminhtml>
</routers>
</admin>
You should also add the dependency to the /app/etc/modules/Mage_CurrencySymbol.xml
<config>
<modules>
<Mage_CurrencySymbol>
<active>true</active>
<codePool>core</codePool>
<depends>
<Mage_Adminhtml />
<Mage_Widget/>
</depends>
</Mage_CurrencySymbol>
</modules>
</config>
There appears to have been a bug/fix raised on github
Go to app/code/core/Mage/CurrencySymbol/etc/config.xml
<args>
<modules>
<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
<currencysymbol after="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol> // Add this new line
</modules>
</args>
Now go to app/etc/modules/Mage_CurrencySymbol.xml
true
core
<depends>
<Mage_Adminhtml /> // Add this new line
<Mage_Widget/>
</depends>

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...
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....
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>
Just an additional notes for those who wants to know about confliction between extensions and possible solutions(just like above case), refer to the following links:
http://www.webshopapps.com/blog/2010/11/resolving-magento-extension-conflicts/
http://sweettoothrewards.com/wiki/index.php/Resolving_extension_conflicts
http://magebase.com/magento-tutorials/magento-extension-clashes-winners-and-loosers/
http://www.magestore.com/blog/2011/12/21/magento-methods-to-resolve-the-module-conflicts-in-magento/
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.

Magento: How to override admin controller outside of adminhtml?

Simply put, I want to override ProcessController which is in the Mage/Index/controllers/Admninhtml/ProcessController.php.
I know how to override the front-end controller, but this gives me a headache for hours now. I can't put it to work. Here's my config file
<?xml version="1.0"?>
<config>
<global>
<models>
<twobuy_index>
<class>Twobuy_Index_Model</class>
</twobuy_index>
</models>
</global>
<admin>
<routers>
<index>
<args>
<modules>
<Twobuy before="Mage_Index">Twobuy_Index</Twobuy>
</modules>
</args>
</index>
</routers>
</admin>
</config>
And the controller declaration
include_once('Mage/Index/controllers/Adminhtml/ProcessController.php');
class Twobuy_Index_Adminhtml_ProcessController extends Mage_Index_Adminhtml_ProcessController
{
I tried overriding reindexAction, but my method never gets called.
Replace <index> with <adminhtml> in your config file. It might just be a copy-paste error but your <Twobuy> tag is incorrectly ended with </Ucon>.
<Twobuy before="Mage_Index">Twobuy_Index</Ucon>
Looks like an error in your XML
<twobuy_index before="Mage_Index">Twobuy_Index</twobuy_index>

Resources