0

I'd like to call $this->getChildHtml('product_type_data') to get product's price outside view.phtml template file.

Currently I have echo $this->getChildHtml('product_type_data') and that outputs contents of 'catalog/product/view/type/default.phtml'.

I need to move it to a file in a custom module(cache hole punch) so that it gets called separately. So in this file I've done:

$block = Mage::app()->getLayout()->createBlock('customerprices/catalog_product_view', $this->getId());
$block->setTemplate('catalog/product/view/type/default.phtml');
$block->setIsLoggedIn(Mage::getSingleton('customer/session')->isLoggedIn());
$out = $block->getChildHtml('product_type_data');

But in this case $out contains an empty string. Do I need to set something on this block so that it will return price html? If so how? I have a current $_product object if that's needed.

I would appreciate any suggestions.


Using Mage::getBlockSingleton(...)

when I use this code:

$thatx = Mage::getBlockSingleton('catalog/product_view');   
$cnamex = get_class($thatx);
echo 'cname: '.$cnamex;

$cnamex does not contain class name(empty string/variable). I consequence I can't run any methods on it.

1 Answer 1

1

If you need only product price block to be rendered you can use like this:

$out=Mage::getBlockSingleton('catalog/product_view')->getPriceHtml($_product);

See getPriceHtml() method of Mage_Catalog_Block_Product_Abstract which is parent class of Mage_Catalog_Block_Product_View

Second Way

Extend your block customerprices/catalog_product_view from Mage_Catalog_Block_Product_Abstract and use it:

class MyCompany_Customerprices_Catalog_Product_View extends Mage_Catalog_Block_Product_Abstract{

}

and

$block = Mage::app()->getLayout()->createBlock('customerprices/catalog_product_view', $this->getId());
$out=$block->getPriceHtml($_product);
2
  • Hi mageUz. Thank you for the reply. I would be really great to use this method to get product object but unfortunately object doesn't load. I run it from module's file(caching injector).
    – Alan
    Jan 15, 2015 at 12:23
  • @Alan see another solution on the answer
    – mageUz
    Jan 15, 2015 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.