I have a scroller showing a collection of products currently on sale, which I call using the following:
$todayDate = Mage::app()->getLocale()->date()->
My colleague recommended using this Magento friendly method to get the price html anywhere:
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
echo $productBlock->getPriceHtml($_product); ?>
If you're already working with a loaded product then you won't need the first line, however my product was from a collection so this was necessary.
To get getPriceHtml() function work correctly in your custom block you need 2 things
1)Make your block type catalog/product
<block type="catalog/product" name="home_page_product" after="default_home_page" template="custom/home_page_product.phtml"/>
2)Pass the product object to getPriceHtml() function
<?php $productObject = Mage::getModel('catalog/product')->load($_product->getId());?>
<?php echo $this->getPriceHtml($productObject, true) ?>
The issue is that getPriceHtml()
function is defined in the Mage_Catalog_Block_Product
block, rather than the standard Mage_Core_Block_Template
. You need to ensure that your block extends the Product block, or you can achieve that in your layout by something like:
<block type="catalog/product" name="blockname" template="path/to/template.phtml">
I haven't tested that, but it should work.
You could also try this:
<?php echo Mage_Catalog_Block_Product::getPriceHtml($_product, true) ?>
Where $_product
relates to the product object.