override orders controller in magento - magento

I have a custom module Permissions_Orders. Here is my code to override orders controller from base admin -
config.xml -
<admin>
<routers>
<adminhtml>
<args>
<modules>
<orders before="Mage_Adminhtml">Orders_Adminhtml_Sales_OrderController</orders>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Permissions/Orders/controllers/Adminhtml/Sales/OrderController.php -
<?php
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
class Permissions_Orders_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
----
}
but still it is calling from base controller. I am not sure, where I am wrong here. Any help is appreciated.

Your config.xml should look like below,
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<orders before="Mage_Adminhtml">Permissions_Orders_Adminhtml</orders>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Notice the change in </orders> node.

In config.xml is enough to specify the namespace and module name where you want to extend the base adminhtml controllers.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Namespace_Adminhtml before="Mage_Adminhtml">Namespace_Adminhtml</Namespace_Adminhtml>
</modules>
</args>
</adminhtml>
</routers>
</admin>

Related

Magento Checkout OnepageController not getting override

I have searched and implemented many answers from stackoverflow but I am not able to override the controller. The question is quite self-explanatory but I will provide the codes to show what I am doing. Maybe someone can guide me in the right direction:
This is my directory structure
This is my config.xml inside etc folder.
<?xml version="1.0"?>
<config>
<modules>
<Zepcom_Checkout>
<version>0.0.1</version>
</Zepcom_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
And this is my controller
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Zepcom_Checkout_OnepageController extends Mage_Checkout_OnepageController {
public function indexAction() {
var_dump("custom"); die;
}
.
. // some overriding code here
.
}
I am really stuck and any help would be appreciated. I am doing a dump to verify the calling of the controller but it keeps calling the Core controller.
You will need to declare a router "routeurfrontend" which is actually the route used by Magento to access your controller.
<?xml version="1.0"?>
<config>
<frontend>
<routers>
<zepcom_checkout>
<use>standard</use>
<args>
<module>Zepcom_Checkout</module>
<frontName>zepcom_checkout</frontName>
</args>
</zepcom_checkout>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
You are missing the </config> closing tag in your config.xml
<?xml version="1.0"?>
<config>
<modules>
<Zepcom_Checkout>
<version>0.0.1</version>
</Zepcom_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Zepcom_Checkout before="Mage_Checkout">Zepcom_Checkout</Zepcom_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

Admin controller not working in Magento

I've used a yeoman generator to build a Magento Module skeleton.
I can access the frontend module simply with:
http://prueba.com/index.php/prueba/index
But I can't make it work the admin. These are my files:
/etc/adminhtml.xml
<config>
<menu>
<prueba>
<title>My Tab</title>
<sort_order>1</sort_order>
<action>adminhtml/prueba/index</action>
</prueba>
</menu>
</config>
/controllers/adminhtml/IndexController.php
<?php
/**
* Index Adminhtml Controller
*
*/
class Altimea_Prueba_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
/**
* Index Action
*/
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
echo 'hello';
}
}
/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Altimea_Prueba>
<version>0.1.0</version>
</Altimea_Prueba>
</modules>
<global>
<models>
<altimeaprueba>
<class>Altimea_Prueba_Model</class>
</altimeaprueba>
</models>
<blocks>
<altimeaprueba>
<class>Altimea_Prueba_Block</class>
</altimeaprueba>
</blocks>
<helpers>
<altimeaprueba>
<class>Altimea_Prueba_Helper</class>
</altimeaprueba>
</helpers>
<resources>
<altimeaprueba_setup>
<setup>
<module>Altimea_Prueba</module>
<class>Altimea_Prueba_Model_Resource_Setup</class>
</setup>
</altimeaprueba_setup>
</resources>
</global>
<frontend>
<layout>
<updates>
<altimeaprueba>
<file>altimeaprueba.xml</file>
</altimeaprueba>
</updates>
</layout>
<routers>
<altimeaprueba>
<use>standard</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</frontend>
<adminhtml>
<layout>
<updates>
<altimeaprueba>
<file>altimeaprueba.xml</file>
</altimeaprueba>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<altimeaprueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</admin>
</config>
When create a magento admin module you can create it in one of two ways. Since you have both a front and backend controller try changing your admin route to <frontname>admin_prueba</frontname> then try http://prueba.com/index.php/admin_prueba/index
<adminhtml>
<menu>
<menu1 translate="title" module="customlist">
<title>ActiveCodeline SampleModule1</title>
<sort_order>60</sort_order>
<children>
<menuitem1 module="SampleModule1">
<title>Menu item 1</title>
<action>{{customlist}}/index</action>
</menuitem1>
<admin>
<routers>
<samplemodule1>
<use>admin</use>
<args>
<module>ActiveCodeline_SampleModule1</module>
<frontname>admin_customlist</frontname>
</args>
</samplemodule1>
</routers>
</admin>
or
<adminhtml>
<menu>
<menu1 translate="title" module="customlist">
<title>ActiveCodeline SampleModule1</title>
<sort_order>60</sort_order>
<children>
<menuitem1 module="SampleModule1">
<title>Menu item 1</title>
<action>{{adminhtml/customlist}}/index</action>
</menuitem1>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Company_CustomList before="Mage_Adminhtml">Foo_Bar_Adminhtml</Company_CustomList>
</modules>
</args>
</adminhtml>
</routers>
</admin>
You have missed to add this in config.xml
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<altimea_prueba after="Mage_Adminhtml">Altimea_Prueba_Adminhtml</altimea_prueba>
</modules>
</args>
</adminhtml>
</routers>
</admin>
In config.xml, change this:
<admin>
<routers>
<altimeaprueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</admin>
To this:
<admin>
<routers>
<altimea_prueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimea_prueba>
</routers>
</admin>
If you want to see your "hello" printed out, in IndexController.php, add exit(); after your echo "hello";
Just a reference
It took me ages to figure out that
<args>
<modules>
<myrandomtag before="Mage_Adminhtml">
My_Module_Adminhtml
</myrandomtag>
</modules>
</args>
IS NOT SAME AS
<args>
<modules>
<myrandomtag before="Mage_Adminhtml">My_Module_Adminhtml</myrandomtag>
</modules>
</args>
So there should be no space or new line inside your random tag

config.xml front name not working while entering front name in url

I have created my custom module that is working fine at backend(Add,Edit,Delete,List) but while I enter frontname in url it shows me page not found error. below is my code
<frontend>
<routers>
<ydg_cylinderworksheet>
<use>standard</use>
<args>
<module>ydg_Cylinderworksheet</module>
<frontName>cylinder-worksheet</frontName>
</args>
</ydg_cylinderworksheet>
</routers>
<layout>
<updates>
<ydg_cylinderworksheet>
<file>ydg_cylinderworksheet.xml</file>
</ydg_cylinderworksheet>
</updates>
</layout>
<translate>
<modules>
<ydg_Cylinderworksheet>
<files>
<default>ydg_Cylinderworksheet.csv</default>
</files>
</ydg_Cylinderworksheet>
</modules>
</translate>
</frontend>
You needd to change your routers tag in your etc/config.xml
<routers>
<cylinderworksheet>
<use>standard</use>
<args>
<module>Ydg_Cylinderworksheet</module>
<frontName>cylinder-worksheet</frontName>
</args>
</cylinderworksheet>
</routers>
....
You need to change your code
<frontend>
<routers>
<cylinderworksheet>
<use>standard</use>
<args>
<module>ydg_Cylinderworksheet</module>
<frontName>cylinderworksheet</frontName>
</args>
</cylinderworksheet>
</routers>
.........

Magento getURL not finding controller of custom module

I am adding in a new mass action for the sales order grid and when I am putting in the url for my action Magento cannot find my controller.
config.xml
<admin>
<routers>
<mymodule>
<use>admin</use>
<args>
<module>Namespace_mymodule</module>
<frontName>frontendname</frontName>
</args>
</mymodule>
</routers>
</admin>
<global>
<events>
<adminhtml_block_html_before>
<observers>
<mymodule>
<class>Namespace_mymodule_Model_Observer</class>
<method>addActions</method>
</mymodule>
</observers>
</adminhtml_block_html_before>
</events>
</global>
observer.php
public function addActions($event)
{
$block = $event->getBlock();
if($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)
{
$block->getMassactionBlock()->addItem('cpsync', array(
'label' => 'Push Orders to CounterPoint',
'url' => Mage::helper("adminhtml")->getUrl("frontendname/adminhtml_index/push/")
));
}
}
Whenever I try to use my mass action it sends me to a 404 redirect page with url
sitename.com/index.php/frontendname/adminhtml_index/push/key/
I think your config.xml is wrong. In the above config.xml, you havent mentioned about the model, block or helper classes. You had just declared about the module and an event. Here is the basic config.xml that you have to follow. Try to modify your config.xml as below.
<?xml version="1.0"?>
<config>
<modules>
<Test_Helloworld>
<version>0.1.0</version>
</Test_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Test_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
</frontend>
<global>
<blocks>
<helloworld>
<class>Test_Helloworld_Block</class>
</helloworld>
</blocks>
<helpers>
<helloworld>
<class>Test_Helloworld_Helper</class>
</helloworld>
</helpers>
</global>
</config>

Overwrite CompareController

I try to override the Core CompareController. Somehow i don't get it done.
I have done some research on the Magento website: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller
But it did not help override the controller.
local/WP/Compare/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<WP_Compare>
<version>0.1.0</version>
</WP_Compare>
</modules>
<global>
<rewrite>
<WP_Compare_Catalog_Product_Compare>
<from><![CDATA[#^/catalog/product/compare/#]]></from>
<to>/compare/catalog/product/compare/</to>
</WP_Compare_Catalog_Product_Compare>
</rewrite>
</global>
</config>
local/WP/Catalog/controllers/Product/CompareController.php
<?php
require_once "Mage/Catalog/controllers/Product/CompareController.php";
class WP_Compare_Catalog_Product_CompareController extends Mage_Catalog_Product_CompareController
{
public function addAction()
{
echo 'Lets GO!';
}
}
?>
Can someone help me with this issue?
Thank you.
Gr.
Lex
This is the solution for my problem.
<?xml version="1.0"?>
<config>
<modules>
<WP_Compare>
<version>0.1.0</version>
</WP_Compare>
</modules>
<frontend>
<routers>
<catalog>
<use>standard</use>
<args>
<modules>
<WP_Compare before="Mage_Catalog">WP_Compare_Catalog</WP_Compare>
</modules>
</args>
</catalog>
</routers>
</frontend>
</config>
You may be need to do something similar to that into your etc.xml:
<frontend>
<routers>
<customer>
<args>
<modules>
<Mymodule_Customer before="Mage_Customer">Mymodule_Customer</Mymodule_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>

Resources