12

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 ?

1
  • search "price.phtml" in catalog.xml in base/default/your_theme, it will be the child block to the block containing list.phtml.
    – Shathish
    Jun 14, 2013 at 6:43

1 Answer 1

12

Product price display

The method getPriceHtml() is defined in the block class Mage_Catalog_Block_Product_Abstract.

The method uses a price renderer which depends on the product type:

$type_id = $product->getTypeId(); // e.g. simple, configurable, bundle, grouped, ...
$this->_preparePriceRenderer($type_id)

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 the catalog/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:

<default>
    <reference name="catalog_product_price_template">
        <action method="addPriceBlockType">
            <type>bundle</type>
            <block>bundle/catalog_product_price</block>
            <template>bundle/catalog/product/price.phtml</template>
        </action>
    </reference>
</default>

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:

$this->_preparePriceRenderer($type_id)
    ->setProduct($product)
    ->setDisplayMinimalPrice($displayMinimalPrice)
    ->setIdSuffix($idSuffix)
    ->toHtml();

The $displayMinimalPrice and $idSuffix variables are optional arguments to the getPriceHtml method.

public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')

The $idSuffix is used in the price template to complete the CSS id of the <span> tag surrounding the actual price, for example:

<span class="price" id="price-excluding-tax-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
5
  • @Vinai could you please suggest something on this stackoverflow.com/questions/20949796/…
    – Mukesh
    Jan 6, 2014 at 13:24
  • If I wanted to get the super attribute pricing would I just use <?php echo $this->getPriceHtml($_product); ?> or do I need to specify what type of pricing? Tiered? Aug 10, 2016 at 18:07
  • Corrent. The method will determine the product type and render the price accordingly.
    – Vinai
    Aug 10, 2016 at 20:03
  • hi @Vinai I tried doing that, but the price stays fixed. It doesn't change when I select a color that is a different price. The top price does change, but not the one down below near add to cart. See here jennyyootest.com/index.php/adelle.html Aug 10, 2016 at 20:34
  • You have to adjust the JavaScript to change both prices.
    – Vinai
    Aug 10, 2016 at 21:39

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.