[Magento] Random price templates

Data dodania wpisu: 17-09-2010

Sometimes there is a need to display the same product price by several templates on the same page. How to create random price template to display it several times, each one themed in another way? Commonly, there is one price template for products:

/template/catalog/product/price.phtml

To continue our purpose, we have to create new method in:

app/code/[namespace]/Mage/Catalog/Block/Product/Abstract.php

by this way:

<?php
public function getPriceHtmlRandomTemplate($product, $template) 
    { 
        return $this->_getPriceBlock($product->getTypeId()) 
            ->setTemplate($template) 
            ->setProduct($product) 
            ->toHtml(); 
    }
?>

This method does load price template from path given in $template variable.

Next we need to do, is ti call this method for example on a Simple Product page:

template/catalog/product/view/type/simple.phtml

The code calling new method could be:

<?php echo $this->getPriceHtmlRandomTemplate($_product, 'catalog/product/random_price_template.phtml') ?>

New file (random_price_template.phtml) is just a copy of price.phtml, however could be modified in another way, ie. for additional CSS styles.

Comments

This entry has no comments yet

Comments closed...

DesignEnd on Facebook

Inspiration