Question

What I have so far:

etc/modules/BugFix_MageAdminhtmlBlockWidgetGrid.xml

<?xml version="1.0"?>
<config>
    <modules>
        <BugFix_MageAdminhtmlBlockWidgetGrid>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml />
            </depends>
        </BugFix_MageAdminhtmlBlockWidgetGrid>
    </modules>
</config>

app/local/BugFix/MageAdminhtmlBlockWidgetGrid/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <BugFix_MageAdminhtmlBlockWidgetGrid>
            <version>1.0.0</version>
        </BugFix_MageAdminhtmlBlockWidgetGrid>
    </modules>
    <global>
        <blocks>
            <mageadminhtmlblockwidgetgrid>
                <class>BugFix_MageAdminhtmlBlockWidgetGrid_Block</class>
            </mageadminhtmlblockwidgetgrid>
            <adminhtml>
                <rewrite>
                    <widget_grid>BugFix_MageAdminhtmlBlockWidgetGrid_Block_Widget_Grid</widget_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

app/local/BugFix/MageAdminhtmlBlockWidgetGrid/Block/Widget/Grid.php

<?php

class BugFix_MageAdminhtmlBlockWidgetGrid_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function getRowUrl($item)
    {
        $res = parent::getRowUrl($item);
        return ($res ? $res : '#');
    }
}

Somehow the above code does not work. It must be something simple...

The bugfix as a module is for Magento 1.4 (and is fixed by Magento in 1.7).

Was it helpful?

Solution

Rewrites do not work when subclassing. In this case, grid classes subclass (extends) the adminhtml grid widget, which means that the name used for the class is the original name, not the rewritten name from the configuration.

POC:

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);

include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();

$block = Mage::app()->getLayout()->createBlock('adminhtml/widget_grid');
echo get_class($block);
//or echo Mage::getConfig()->getBlockClassName('adminhtml/widget_grid');

$block = new Mage_Adminhtml_Block_Widget_Grid;
echo get_class($block);

In this case you will need to copy the path and file from the core codepool to the local codepool and change the definition in there. Because of the include path precedence the definition from the local codepool will be used. You must account for this in an upgrade, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top