Last active
July 10, 2019 16:10
-
-
Save grafikchaos/6685d51064b4b1da68b4 to your computer and use it in GitHub Desktop.
Revisions
-
Josh J. revised this gist
Aug 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,7 +67,7 @@ In this example, the community module will be the `Xtento_GridActions` module an // explicitly require parent controller b/c controllers are not autoloaded require_once(Mage::getModuleDir('controllers','Xtento_GridActions') .DS. 'Adminhtml' .DS. 'Gridactions' .DS. 'PrintController.php'); class My_Module_Adminhtml_Gridactions_PrintController extends Xtento_GridActions_Adminhtml_GridActions_PrintController { ... } -
Josh J. revised this gist
Aug 12, 2014 . 1 changed file with 77 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,80 @@ # Overview For helpful resources on overriding Magento controllers, blocks, models, helpers, etc. see Josh Pratt's post on [Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)](http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/) Here's a [list of search results](http://bit.ly/1pMvExF) that I've found most helpful; otherwise good luck with the Googling! ## Overriding Controllers ### Overriding Magento Core Admin controllers ```xml <!-- in your app/code/local/etc/config.xml file --> <config> <admin> <routers> <adminhtml> <args> <modules> <My_Module before="Mage_Adminhtml">My_Module</My_Module> </modules> </args> </adminhtml> </routers> </admin> </config> ``` **And don't forget to `include_once` or `require_once` the parent controller!** ```php <?php // explicitly require parent controller b/c controllers are not autoloaded require_once(Mage::getModuleDir('controllers','Mage_Adminhtml') .DS. 'Catalot' .DS. 'Product' .DS. 'AttributeController.php'); class My_Module_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_Catalog_Product_AttributeController { ... } ``` ### Overriding Community module's Admin controllers In this example, the community module will be the `Xtento_GridActions` module and specifically the `Xtento_GridActions_Adminhtml` controllers. ```xml <!-- in your app/code/local/etc/config.xml file --> <config> <admin> <routers> <adminhtml> <args> <modules> <My_Module before="Xtento_GridActions_Adminhtml">My_Module_Adminhtml</My_Module> </modules> </args> </adminhtml> </routers> </admin> </config> ``` **And don't forget to `include_once` or `require_once` the parent controller!** ```php <?php // explicitly require parent controller b/c controllers are not autoloaded require_once(Mage::getModuleDir('controllers','Xtento_GridActions') .DS. 'Adminhtml' .DS. 'Gridactions' .DS. 'PrintController.php'); class MY_MODULE_Adminhtml_Gridactions_PrintController extends Xtento_GridActions_Adminhtml_GridActions_PrintController { ... } ``` # Debugging Controller Rewrites See this awesome [Stack Overflow response](http://stackoverflow.com/a/15834524) from [benmarks](http://stackoverflow.com/users/833795/benmarks) -
Josh J. revised this gist
Aug 12, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -146,4 +146,5 @@ Array ``` > Wherever you see more than one subarray, there is a controller directory rewrite. > > [benmarks](http://stackoverflow.com/a/15834524) -
Josh J. revised this gist
Aug 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -146,4 +146,4 @@ Array ``` > Wherever you see more than one subarray, there is a controller directory rewrite. > [benmarks](http://stackoverflow.com/a/15834524) -
Josh J. created this gist
Aug 12, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,149 @@ See this awesome [Stack Overflow response](http://stackoverflow.com/a/15834524) from [benmarks](http://stackoverflow.com/users/833795/benmarks) **test.php** ```php <?php # test.php => (http://mysite.dev/test.php) ini_set('display_errors',1); error_reporting(E_ALL^E_STRICT); include 'app/Mage.php'; Mage::setIsDeveloperMode(true); Mage::app(); // =================================================================================================== // FIRST TEST - check if your module is loading correctly // =================================================================================================== // replace `COMMUNITY_MODULE` with the module you are looking to override require_once Mage::getModuleDir('controllers','COMMUNITY_MODULE') . DS . 'path/to/CONTROLLER_NAME.php'; // replace `MY_MODULE` with the module you are looking to override require_once Mage::getModuleDir('controllers','MY_MODULE') . DS . 'path/to/CONTROLLER_NAME.php'; $controller = new MY_MODULE_CONTROLLER_NAME( Mage::app()->getRequest(), // required constructor arg Mage::app()->getResponse() // required constructor arg ); echo get_class($controller); // =================================================================================================== // END FIRST TEST - check if your module is loading correctly // // Visit yoursite.com/test.php and you should see your controller class name. // If you see an error, or you see nothing, something fairly low-level is broken. // If the error message is unintuitive, check that your module config is being // merged and move from there. // // If the class instantiates, we know the following: // // + Base module config is good // + File structure is appropriate for the config // + The explicit include is good // =================================================================================================== // =================================================================================================== // SECOND TEST - sniff for controller rewrites // =================================================================================================== // you can change 'standard' to 'admin' if you're debugging adminhtml controller rewrites $router = Mage::app()->getFrontController()->getRouter('standard'); /* @var $router Mage_Core_Controller_Varien_Router_Standard */ $reflection = new ReflectionClass($router); $modules = $reflection->getProperty('_modules'); $modules->setAccessible(true); echo "<pre>"; print_r($modules->getValue($router)); echo "</pre>"; // =================================================================================================== // END SECOND TEST - sniff for controller rewrites // =================================================================================================== ``` The second test should output something similar to the below example: ```php Array ( [manage] => Array ( [0] => Mage_Index_Adminhtml [1] => Mage_Paygate_Adminhtml [2] => Mage_Paypal_Adminhtml [3] => Mage_Widget_Adminhtml [4] => Mage_Oauth_Adminhtml [5] => Mage_Authorizenet_Adminhtml [6] => Mage_Bundle_Adminhtml [7] => Mage_Centinel_Adminhtml [8] => Mage_Compiler_Adminhtml [9] => Mage_Connect_Adminhtml [10] => Mage_Downloadable_Adminhtml [11] => Mage_ImportExport_Adminhtml [12] => Mage_Api2_Adminhtml [13] => Mage_PageCache_Adminhtml [14] => Mage_XmlConnect_Adminhtml [15] => Ash_Slideshow_Adminhtml [16] => Ash_Up_Adminhtml [17] => Bubble_Launcher_Adminhtml [18] => EM_Megamenupro_Adminhtml [19] => Ebizmarts_AbandonedCart_Adminhtml [20] => Ebizmarts_MageMonkey_Adminhtml [21] => Ebizmarts_Mandrill_Adminhtml [22] => Fishpig_Wordpress_Adminhtml [23] => Fooman_Common_Adminhtml [24] => Fooman_PdfCustomiser_Adminhtml [25] => Infomodus_Upslabel_Adminhtml [26] => Webtex_Giftcards_Adminhtml [27] => Pan_Authorizenetcim [28] => Pan_Gridactions_Adminhtml [29] => Xtento_GridActions_Adminhtml [30] => Xtento_OrderExport_Adminhtml [31] => Mage_Adminhtml [32] => Phoenix_Moneybookers [33] => Mage_Captcha_Adminhtml [34] => Mage_CurrencySymbol_Adminhtml ) ... MORE MODULES (excluded for brevity) ... [upslabel] => Array ( [0] => Pan_Infomodusupslabel [1] => Infomodus_Upslabel ) [giftcards] => Array ( [0] => Pan_Giftcards [1] => Webtex_Giftcards ) [orderedit] => Array ( [0] => Pan_OrderEdit [1] => TinyBrick_OrderEdit ) [gridactions] => Array ( [0] => Pan_Gridactions [1] => Xtento_GridActions ) ) ``` > Wherever you see more than one subarray, there is a controller directory rewrite. > - [benmarks](http://stackoverflow.com/a/15834524)