4

How do I create a custom price.phtml file and display it on the product view page?

Use case: I have updated the price.phtml file under product > view to add rich snippets / structured data. And, I would like to create a new price.phtml file so that I can use it for 'Related Products' which appear on the Product View page.

=== Update ===

I have updated catalog.xml as below,

<catalog_product_view> 
    <reference name="right">  
            <block type="enterprise_targetrule/catalog_product_list_related" name="catalog.product.related" as="relatedProducts" template="targetrule/catalog/product/list/related.phtml"> 
                <action method="setColumnCount"><columns>3</columns></action>
                <block type="enterprise_targetrule/catalog_product_item" name="catalog.product.related.item" template="targetrule/catalog/product/list/related/item.phtml">  
                     <action method="addPriceBlockType">  
                        <type>simple</type>  
                        <block name="myprice">catalog/product_price</block>  
                        <template>catalog/product/myprice.phtml</template>  
                    </action>                     
                </block>  
            </block>  
        </reference>  
</catalog_product_view>

Note that I have only added the simple price type block for now. And, the default related products block is being overridden by a module (as you can see in the above XML).

In myprice.phtml, I just have a simple echo statement.

As a follow up, can I call the custom price template in the related item block as below?

<?php echo $this->getChildHtml('myprice'); ?>
8

Ugh. So messy.

  1. Create your custom price template(s) as desired
  2. Determine which block is "the related products block"; catalog.product.related.item works on a stock theme.
  3. For each product type (simple, configurable, etc.), add a price block template as needed.

You can test this out in your custom theme's layout.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <catalog_product_view>
        <reference name="catalog.product.related.item">
            <action method="addPriceBlockType">
                <type>simple</type>
                <block>catalog/product_price</block>
                <template>path/to/custom/price.phtml</template>
            </action>
        </reference>
    </catalog_product_view>
</layout>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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