0

I'm trying to rewrite some blocks from adminhtml (Magento 1.9.1.1). Here's my code in my extension's config.xml:

...
<global>
  <blocks>
    <adminhtml>
      <rewrite>
        <report_grid>Mypackage_Myextension_Block_Adminhtml_Report_Grid</report_grid>
        <widget_grid_column_filter_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Date</widget_grid_column_filter_date>
        <widget_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
        <widget_grid_column_filter_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Datetime</widget_grid_column_filter_datetime>
        <widget_grid_column_renderer_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Datetime</widget_grid_column_renderer_datetime>
        <report_sales_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Report_Sales_Grid_Column_Renderer_Date</report_sales_grid_column_renderer_date>
      </rewrite>
    </adminhtml>
  </blocks>
</global>
...

Oddly enough, all blocks were overwritten except report_grid which is Mage_Adminhtml_Block_Report_Grid.I couldn't find the issue. I have a file called Grid.php in app/code/local/Mypackage/Myextension/Block/Adminhtml/Report. What should I do? Is there any other way to rewrite this block?

UPDATE:

Here's output of Mage::getConfig()->getNode('global/blocks/adminhtml')->asNiceXml();:

<adminhtml>
    <class>Mage_Adminhtml_Block</class>
    <rewrite>
        <report_grid>Mypackage_Myextension_Block_Adminhtml_Report_Grid</report_grid>
        <widget_grid_column_filter_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Date</widget_grid_column_filter_date>
        <widget_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
        <widget_grid_column_filter_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Datetime</widget_grid_column_filter_datetime>
        <widget_grid_column_renderer_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Datetime</widget_grid_column_renderer_datetime>
        <report_sales_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Report_Sales_Grid_Column_Renderer_Date</report_sales_grid_column_renderer_date>
    </rewrite>
</adminhtml>

And this is my Mypackage_Myextension_Block_Adminhtml_Report_Grid class:

class Mypackage_Myextension_Block_Adminhtml_Report_Grid extends Mage_Adminhtml_Block_Report_Grid
{
    public function __construct() {
        parent::__construct();
        die("Houston the eagle has landed. \o/");
        $this->setTemplate('myextension/report/grid.phtml');
    }
}

But it never called. If I die in Mage_Adminhtml_Block_Report_Grid it will die.

4

This is very odd, do you have multiple rewrites ? Prefix your name to 'zzzzzzz' and the GLOB (xml files) function will put your rewrite in as last. But maybe check the next line first:

Mage_Core_Model_Config: line(1227)

    $config = $this->_xml->global->{$groupType.'s'}->{$group};
    // First - check maybe the entity class was rewritten
    $className = null;
    if (isset($config->rewrite->$class)) {
        $className = (string)$config->rewrite->$class;
    } 

So, you can do the next test/check:

Test:

<?php

include_once(dirname(dirname(__DIR__)).'/mageInit.php');

mageTest::initMage();
echo Mage::getConfig()->getGroupedClassName('block', 'adminhtml/report_grid');
echo Mage::getConfig()->getNode('global/blocks/adminhtml')->asNiceXml();

Will give me this output when i copy/paste your XML in to my (empty) project:

Mypackage_Myextension_Block_Adminhtml_Report_Grid
<adminhtml>
   <class>Mage_Adminhtml_Block</class>
   <rewrite>
      <report_grid>Mypackage_Myextension_Block_Adminhtml_Report_Grid</report_grid>
      <widget_grid_column_filter_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Date</widget_grid_column_filter_date>
      <widget_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
      <widget_grid_column_filter_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Filter_Datetime</widget_grid_column_filter_datetime>
      <widget_grid_column_renderer_datetime>Mypackage_Myextension_Block_Adminhtml_Widget_Grid_Column_Renderer_Datetime</widget_grid_column_renderer_datetime>
      <report_sales_grid_column_renderer_date>Mypackage_Myextension_Block_Adminhtml_Report_Sales_Grid_Column_Renderer_Date</report_sales_grid_column_renderer_date>
   </rewrite>
</adminhtml>

The best thing to do is stop using rewrites and the configuration part of Magento. And start using the Event-Driven part of Magento. Especialy if your going to sell your modules to others.

Greating, good luck and happy hacking !

  • As far as I can tell, there are no other rewrites on this block. I tried your test in another way and it seems Magento won't overwrite my block. How can I find out why? – Pedram Behroozi Sep 27 '15 at 14:34
  • That isn't possible. If config says your file is called: Mypackage_Myextension_Block_Adminhtml_Report_Grid than that file will be used. (Mage_Core_Model_Config on line 1227). If you have a typo you will get a error like can't find : MAGE_My...._My..._, because if it doesn't exists like Core than it will prefix with Mage like: Mage_Core. And can't be a typo because i have copy pasted from you and it works. Sorry to ask, but did you flush your config.xml cache ? Please post: Mage::getConfig()->getNode('global/blocks/adminhtml')->asNiceXml(); – Roger Keulen Sep 27 '15 at 19:30
  • Also a good test you can try, but it's a ugly one. Open your block /Adminhtml/Report/Grid.php add a constructor with 'die("Houston the eagle has landed. \o/");' – Roger Keulen Sep 27 '15 at 19:38
  • Please see my update. – Pedram Behroozi Sep 28 '15 at 5:48
  • Sorry, but the DIE schould be in the file your overwriting. Just to be shure where not trying to find a none-existing problem. What is the layout handle your using or are your creating the block in code ? I did not work with reports before, but i can't find a normal adminhtml_report_grid handle in report.xml (xml update files). Maybe a good test is to create the block from code in a unit test. echo get_class(Mage::getBlock('adminhtml/report_grid')); – Roger Keulen Sep 29 '15 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.