1

I want get current block in my observer, for example I have observe event

        <catalog_block_product_list_collection>
            <observers>
                <mycompany_category_list_collection>
                    <type>singleton</type>
                    <class>mycompany/category</class>
                    <method>sendProductImpressionAfterLoad</method>
                </mycompany_category_list_collection>
            </observers>
        </catalog_block_product_list_collection>

this is event dispath in block reder category.... I can get this block class, name, file, type or other information for help me indetification this block in my method.

3

Try your stuff with below example:

public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer) {

 $block = $observer->getBlock();

if($block instanceof Mage_Page_Block_Html_Pager) {
        $collection = $block->getCollection();
        $pages = $block->getPages();
    }

}
2
  • edit your answer, this is good idea, you genius, thanks I try this and mark you answer as correct after, sorry for my English. – Naumov Jul 19 '16 at 13:23
  • Yes is answer help me resolve my trouble. – Naumov Jul 19 '16 at 13:38
1

Use bellow code in your observer.php file

public function sendProductImpressionAfterLoad($observer)
{
    $block = $observer->getEvent()->getBlock();
    /*get Block class*/
    echo get_class($block);
    /*get Block name */
    echo $block->getName()
   /*get Block type*/
    echo $type = $block->getType();
}
1
  • getEvent()->getBlock() return null because Mage::dispatchEvent('catalog_block_product_list_collection', array( 'collection' => $this->_getProductCollection() )); event not dispath block... – Naumov Jul 19 '16 at 13:23
1

You cannot get the block that dispatches the event catalog_block_product_list_collection.
The event is dispatched like this

 Mage::dispatchEvent('catalog_block_product_list_collection', array(
    'collection' => $this->_getProductCollection()
 ));

There is no reference passed to the observer about who dispatches it.
Only the collection is passed on.
You should try to observe the block rendering if you want block specific actions.

2
  • I know but I can use other observer as say @Pallavi – Naumov Jul 19 '16 at 13:39
  • @Naumov. Yep. you should take that approach. – Marius Jul 19 '16 at 13:54

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.