0

I have a third party extension on Magento 1.9 which has the phtml file to display list of favorite brands for the logged in user. It the phtml file of this extension, it does the following to get the list:

$_helper = $this->helper('personalize');
$FavBrands= $this->getBrands();
$count = count($FavBrands);

I want to be able to call the above in other places around the store. I see from above code, it uses ($this). What does it mean, and what change should I do from above to be able to call it getBrands() in for instance (product page).

Note that I am not looking to immediatly insert the block of the third party extension into other pages. I want to reuse their functions to do other things.

0

In magento phtml file ($this) is represent the block class of the file. In that block file getBrands() function writen.

To get block file path there are 2 ways,

  1. Check your extension layout file avilable in current theme.

  2. In above phtml file just write

    echo get_class($this);
    

So it will return you the class path.

Now, if you need to call that function in another pages, just do following things,

$newobj = new YOUR_CLASS_PATH(); //YOUR CLASS PATH FROM STEP-2
$FavBrands= $newobj ->getBrands();
$count = count($FavBrands);
0

in Magento you can call any method of any block in an phtml file by referencing block.

you need to create Block instance in your phtml file & then you can call any methods of that block

in you phtml you need to write

$FavBrandsblock=  $this->getLayout()->createBlock('block_keyfrom_confignxml/blockfilepath');

$FavBrands= $FavBrandsblock->getBrands();
$count = count($FavBrands);

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.