23

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>
2
  • Can you please update your answer with the code you've used to add the products? Commented May 18, 2014 at 8:51
  • Hi I've used the same as I do for version 8. 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>
    – rufus
    Commented May 18, 2014 at 9:55

1 Answer 1

24

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.

4
  • Can you please point in which file this code has to be added in rwd theme? Commented Apr 28, 2015 at 5:54
  • Adding what file would help, as well as lines. The above does not match the code in the list.phtml Commented Nov 5, 2015 at 3:51
  • Hi philip it could be that the most recent version of magento has fixed this problem. Commented Nov 6, 2015 at 11:05
  • which main template needs to be copied? list.phtml?
    – Pixelomo
    Commented Jan 12, 2016 at 11:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.