BlockObserver is a Magento extension for rewrite blocs by event of method _toHtml using observer, without actually rewriting blocks.
Copy module to magento directory:
app/code/local/Slv/BlockObserver
toapp/code/local/Slv/BlockObserver
app/etc/modules/Slv_BlockObserver.xml
toapp/etc/modules/Slv_BlockObserver.xml
$ modman clone [email protected]:sergoslav/BlockObserver.git
Add to composer.json :
"repositories": [
{
"type": "vcs",
"url": "https://github.com/sergoslav/BlockObserver.git"
}
],
"require":{
"slv/block-observer":"*"
}
Add to .../Slv/BlockObserver/etc/config.xml
in section <block_events>...</block_events>
data by rewrite block:
<config>
...
<global>
...
<block_events>
<!--Example rewrite of block Mage_Adminhtml_Block_Sales_Order_Grid:-->
<Mage_Adminhtml_Block_Sales_Order_Grid>
<observers>
<type>singleton</type>
<block>blockObserver/adminhtml_sales_order_grid</block>
<method>Mage_Adminhtml_Block_Sales_Order_Grid</method>
<parent>true</parent>
</observers>
</Mage_Adminhtml_Block_Sales_Order_Grid>
</block_events>
...
</global>
...
</config>
Create block for add observer for method _toHtml() of block:
class Slv_BlockObserver_Block_Adminhtml_Sales_Order_Grid extends Mage_Core_Block_Template
{
/**
* Function for rewrite method _toHtml of block Mage_Block
*
* @param $block Mage_Adminhtml_Block_Sales_Order_Grid
*/
public function Mage_Adminhtml_Block_Sales_Order_Grid($block)
{
$block->addColumnAfter(
'additional_column',
array(
'header'=> Mage::helper('sales')->__('Additional Column'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
),
'status'
);
}
}