Magento - using $this->getPriceHtml on custom page template

后端 未结 4 791
天命终不由人
天命终不由人 2021-02-02 14:02

I have a scroller showing a collection of products currently on sale, which I call using the following:

$todayDate  = Mage::app()->getLocale()->date()->         


        
相关标签:
4条回答
  • 2021-02-02 14:50

    My colleague recommended using this Magento friendly method to get the price html anywhere:

    <?php $_product = Mage::getModel('catalog/product')->load($product->getId());
          $productBlock = $this->getLayout()->createBlock('catalog/product_price');
          echo $productBlock->getPriceHtml($_product); ?>
    

    If you're already working with a loaded product then you won't need the first line, however my product was from a collection so this was necessary.

    0 讨论(0)
  • 2021-02-02 14:57

    To get getPriceHtml() function work correctly in your custom block you need 2 things

    1)Make your block type catalog/product

    <block type="catalog/product" name="home_page_product" after="default_home_page" template="custom/home_page_product.phtml"/>
    

    2)Pass the product object to getPriceHtml() function

    <?php $productObject = Mage::getModel('catalog/product')->load($_product->getId());?>
    <?php echo $this->getPriceHtml($productObject, true) ?>
    
    0 讨论(0)
  • 2021-02-02 14:58

    The issue is that getPriceHtml() function is defined in the Mage_Catalog_Block_Product block, rather than the standard Mage_Core_Block_Template. You need to ensure that your block extends the Product block, or you can achieve that in your layout by something like:

    <block type="catalog/product" name="blockname" template="path/to/template.phtml">
    

    I haven't tested that, but it should work.

    0 讨论(0)
  • 2021-02-02 15:01

    You could also try this:

    <?php echo Mage_Catalog_Block_Product::getPriceHtml($_product, true) ?>
    

    Where $_product relates to the product object.

    0 讨论(0)
提交回复
热议问题