Magento 1.9 – Show Products on Homepage

ce-1.9.0.1cmsmagento-1.9product-listrwd-theme

Just installed magento 1.9 and have fallen on the first hurdle.
I've created a product and have used suggestions from previous versions to display the product on the homepage but am getting the following message

Fatal error: Call to a member function getSortedChildren() on a non-object in app/design/frontend/rwd/default/template/catalog/product/list.phtml on line 180

Any help gratefully received.

In the content section of homepage I have…

<div class="page-title"> 
    <h2>Our Latest Products</h2> 
</div> 
<p>{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}</p>

Best Answer

The problem is the new rwd design has two child blocks for the product list:

<block type="core/text_list" name="product_list.name.after" as="name.after" />
<block type="core/text_list" name="product_list.after" as="after" />

And in the template itself there are not checks to see if these are present before they are attempted to be loaded and used.

A quick fix would be to use a different template that is a copy of the main template but with the following edits:

<?php
$_nameAfter = $this->getChild('name.after');
// New if here
if($_nameAfter):
    $_nameAfterChildren = $_nameAfter->getSortedChildren();
    foreach($_nameAfterChildren as $_nameAfterChildName):
        $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
        $_nameAfterChild->setProduct($_product);
        ?>
        <?php echo $_nameAfterChild->toHtml(); ?>
    <?php endforeach; ?>
<?php endif; ?>

<?php
//set product collection on after blocks
$_afterChildren = $this->getChild('after');
if ($_afterChildren):
    $_afterChildren = $this->getChild('after')->getSortedChildren();
    foreach($_afterChildren as $_afterChildName):
        $_afterChild = $this->getChild('after')->getChild($_afterChildName);
        $_afterChild->setProductCollection($_productCollection);
    ?>
    <?php echo $_afterChild->toHtml(); ?>
<?php endforeach; ?>
<?php endif; ?>

The name.after occurs twice in the template but the after appears just one. One final thing to note is that the default rwd css hides the actions section of the product list on the cms pages.

Related Topic