BlockObserver Magento module
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
README.md
composer.json
modman

README.md

BlockObserver Magento module

BlockObserver is a Magento extension for rewrite blocs by event of method _toHtml using observer, without actually rewriting blocks.

Installation

Standard installation

Copy module to magento directory:

  • app/code/local/Slv/BlockObserver to app/code/local/Slv/BlockObserver
  • app/etc/modules/Slv_BlockObserver.xml to app/etc/modules/Slv_BlockObserver.xml

Using modman

    $ modman clone git@github.com:sergoslav/BlockObserver.git

Using Composer

    Add to composer.json :
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/sergoslav/BlockObserver.git"
        }
    ],
    "require":{
            "slv/block-observer":"*"
        }

Using

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'
        );
    }
}