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>
  • Can you please update your answer with the code you've used to add the products? – Sander Mangel May 18 '14 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 May 18 '14 at 9:55
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.

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

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