12,Jun
2013

How to use priceHtml() function on custom extension or module file?

I am sure that you all must have faced the difficulty to display the price including tax, special price etc. in a way how Magento works while developing a custom module or an extension.

Magento uses blocks terminology in its architecture to display the views. Blocks are classes in Magento modules which handles the content output and communicate directly with phtml templates. Data and information is passed to the template through Block methods, implemented in the block class.

$this->getPriceHtml () Method is used in the templates to display the product price in html format. This method returns the rendered html with currency symbol and defined number format. It also displays the products special price and minimum price.

However this is a very useful method for custom created templates or content blocks where we need to display the formatted price but still this function cannot be used directly with the $product object.

By default we can use getPrice() function to display the price of the product though it does not allow to include additional features such as tax and special prices. For including that, we need to implement the following code.

$this->getPriceHtml ($_product);.

To use this function on any custom template page or even in a controller, use the following code:

<?php
//this is an example code and can be used in any .phtml file or controller class
$product_block = new Mage_Catalog_Block_Product;

//$product is product object
echo $product_block->getPriceHtml($product);

//if inside a loop than unset the instance.
unset($product_block);
?>
									

I hope it will be helpful to you.

Thanks,

Post by Bhavin

Bottom Shadow
Comments (1)
  1. cheap prom dresses uk

    September 18, 2013

    You have brought up a very excellent details , regards for the post.

Leave a Reply

Your email address will not be published. Required fields are marked *


− 2 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


United States, United Kingdom, Australia, Italy, Brazil, Canada, Spain, France, Germany, South Africa, New Zealand, Netherlands, Austria, Switzerland, Estonia, Ireland, Romania, Egypt, Belgium, Algeria, Albania, Belarus, Jamaica.
Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: