Catalog Product listing page's template file is list.phtml
. Where the rendering of all the products in category happens using foreach
loop.
I am confused about the rendering of the price.phtml
. Because there is no block for it in handle <catalog_category_default>
Now, <?php echo $this->getPriceHtml($_product, true) ?>
returns price of the product.
How this method is linked to price.phtml
?
Best Answer
Product price display
The method
getPriceHtml()
is defined in the block classMage_Catalog_Block_Product_Abstract
.The method uses a price renderer which depends on the product type:
The price renderer is a block with an associated template. Both depend on the product type.
If there is no block or template defined for the specified product type, it defaults to the
catalog/product_price
block and thecatalog/product/price.phtml
template.Where are the price renderers and templates for product types defined?
The price blocks and renderers usually are specified using layout XML, so modules which add new product types can easily add their own renderers, too. For example. the bundled product adds it's price renderer as follows in the
bundle.xml
layout file:Custom price templates or renderers
Using the same mechanism it's also possible to override the default renderers. If you want to just change the template, and keep the default price block type, simply call
addPriceBlockType
in the layout file with the default block (see above) and your template.Rendering the price block
The code to actually render the price block looks like this:
The
$displayMinimalPrice
and$idSuffix
variables are optional arguments to thegetPriceHtml
method.The
$idSuffix
is used in the price template to complete the CSS id of the<span>
tag surrounding the actual price, for example: