Search code examples
magentoblockphp

Magento separate price.phtml


How can I add a new price template to the category view (template/catalog/product/list.phtml) without changing the price template that is used in (template/catalog/product/view.phtml)? Both files uses the template/catalog/product/price.phtml, but I need a separate price template in template/catalog/product/list.phtml.


Solution

  • Copy app/code/core/Mage/Catalog/Block/Product.php to app/code/local/YourModule/Catalog/Block/Product.php(about the detail of making your own module, you should see other document).

    In the copied file, about Line 61, change

    public function getPriceHtml($product)
        {
            $this->setTemplate('catalog/product/price.phtml');
            $this->setProduct($product);
            return $this->toHtml();
        }
    

    to

    public function getPriceHtml($product)
        {
            $this->setTemplate('catalog/product/your_price.phtml');
            $this->setProduct($product);
            return $this->toHtml();
        }
    

    you can custom the view of price in your_price.phtml.