I am creating a random list of products that refreshes every hour. I've got most of it done but there is one problem: getPriceHTML is returning NULL. This function is used in the normal category product lists and works perfectly there.

This code does give a correct getPriceHTML

$_productCollection = Mage::getModel('catalog/product')->getCollection();

But what I need is to get a random product, no matter what category it is in, so that is not an option.

The following code is the code I use to get random products:

$this->_productCollection = Mage::getResourceModel('catalog/product_collection');
$this->_productCollection->setPage(1, 3);

And later on:

foreach($this->_productCollection AS $_product)
    echo $this->getPriceHtml($_product, true);

For simple products this does give the correct price, but it returns NULL for grouped products. Yes, I am extending to Mage_Catalog_Block_Product.

Please keep in mind that I know that there are other functions to get the price, but I specifically want to know why this isn't working as it should.

  • The default method looks like this "public function getPriceHtml($product)" Do you have customised the getPriceHtml method that requires the additional true param? Jan 8 '14 at 8:41
  • I will check it out, If so, I have not done it myself. This is the code that has been used in the list.phtml Jan 8 '14 at 8:42
  • @Fooman I am not seeing why they added the true at that function, since it doesn't seem to be overridden in any way. Removing it still gives the same result too anyway. Jan 8 '14 at 8:47

Please take a look at the two implementations for getPriceHtml()


public function getPriceHtml($product)
    return $this->toHtml();



public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')
    return $this->_preparePriceRenderer($product->getTypeId())

extending from the Abstract block should help in getting the correct renderer.

  • As a sidenote Mage_Catalog_Block_Product does not extend from the Abstract block, sigh... Jan 8 '14 at 8:50
  • So that is where the true came from, that explains a lot! Extending to Mage_Catalog_Block_Product_Abstract did fix it for me, thanks! Jan 8 '14 at 8:53

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.