Magento - use the alternative "price.phtml" (in addition to the existing one)

I am looking for a way to have an alternative template/catalog/product/price.phml used in one particular place and continue to use the existing price.phtml file in all other places.

To explain further, I need to display the regular price, and then another special price right below it - but only on the product page (for the main product displayed). This special price is not a price that can be calculated according to the catalog price rules, so I wrote my own module for calculation. So, wherever I show prices, I want to display using the regular file ol template/catalog/product/price.phtml ... but for the product page (the main product is unrelated, upsells, etc.). I want to use my own template/catalog/product/price-custom.phtml template file. Can anyone help?

Usually I just look in the XML layout files (e.g. catalog.xml) to find these types of things, but price.phtml is a special kind - it's not that simple. And for life, I can’t understand if there is an easy way to change it conditionally on the page you are viewing. I know that I can just update price.phtml to always print this extra price, and then use css to hide the price everywhere, but I would prefer not to, if possible.

(You may also know that I have only simple products.)

+4
source share
5 answers

Or in your php block.

See an example here:

Mage_Catalog_Block_Product_Abstract

 protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml'; protected $_tierPriceDefaultTemplate = 'catalog/product/view/tierprices.phtml'; 
+1
source

This can be done in the layout xml file:

 <layout> <PRODUCT_TYPE_simple> <reference name="product.clone_prices"> <action method="setTemplate"> <template>catalog/product/price-custom.phtml</template> </action> </reference> </PRODUCT_TYPE_simple> </layout> 
+5
source

Create a local.xml file, put it in app/frontend/default/YOURTEMPLATE/layout

In the local.xml file add:

 <?xml version="1.0" encoding="UTF-8"?> <layout> <!-- Override price template on product view page --> <PRODUCT_TYPE_simple> <reference name="product.info.simple"> <action method="setTemplate"> <template>catalog/product/price_product_page.phtml</template> </action> </reference> </PRODUCT_TYPE_simple> <!-- /Override price template on product view page --> </layout> 

Create a copy of catalog/product/price.phtml and put it in YOURTEMPLATE/templates/product/product_price_page.phtml

This will replace price.phtml in the template and replace it with product_price_page.phtml

+5
source

I had a similar requirement recently when a different pricing template for a product page was the preferred solution.

The price block, apparently, is something special in Magento (at least in the RWD theme), it is defined in catalog.xml as just the type and name of the block in the <default/> grip:

 <block type="catalog/product_price_template" name="catalog_product_price_template" /> 

If you look at how some of the main layout files define a price template, you will find examples like this (from bundle.xml):

 <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> 

They call a method called addPriceBlockType , which you can find in Mage_Catalog_Block_Product_Abstract

Based on this and after a little experiment, I found the following solution for me:

 <catalog_product_view> <reference name="product.info"> <action method="addPriceBlockType"> <type>simple</type> <block>catalog/product_price</block> <template>catalog/product/price_product_page.phtml</template> </action> <action method="addPriceBlockType"> <type>configurable</type> <block>catalog/product_price</block> <template>catalog/product/price_product_page.phtml</template> </action> <!-- Set for each product type as necessary eg bundled, virtual etc... --> </reference> </catalog_product_view> 
+1
source

The correct way to achieve it:

 <PRODUCT_TYPE_simple> <reference name="product.info.simple"> <action method="addPriceBlockType"><type>simple</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action> </reference> </PRODUCT_TYPE_simple> <PRODUCT_TYPE_configurable> <reference name="product.info.configurable"> <action method="addPriceBlockType"><type>configurable</type><block>catalog/product_price</block><template>catalog/product/price-product-page.phtml</template></action> </reference> </PRODUCT_TYPE_configurable> 

...

0
source

Source: https://habr.com/ru/post/1336319/


All Articles