1

I'm trying to add products to a page. I used this code in contents of the page.

<p>{{block type="catalog/product_list" category_id="4" template="catalog/product/list.phtml"}}</p>.

And I got this error.

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

How to fix it?

1 Answer 1

4

Ha. I think you stumbled on a bug in the 1.9 theme. .
There is this piece of code in the product/list.phtml.

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

This code makes it impossible to use {{block}} directives with this template.
You can fix it by creating your own theme that has as parent the rwd theme and change the code above to

<?php
    if (is_object($this->getChild('name.after'))) { 
        $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
        foreach($_nameAfterChildren as $_nameAfterChildName):
            $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
            $_nameAfterChild->setProduct($_product);
         ?>
         <?php echo $_nameAfterChild->toHtml(); ?>
    <?php endforeach; ?> 
 <?php } ?>
6
  • Yeah, it is magento 1.9, but when I tried to tag that one, this platform told me that I should have 150 credits which I don't have.... Will try your's now. Commented Jun 2, 2014 at 9:36
  • @AjayKulkarni. I've re-taged your question.
    – Marius
    Commented Jun 2, 2014 at 9:40
  • Thank you, Marius. I edited that phtml file as you told and it is returning one more error. Fatal error: Call to a member function getSortedChildren() on a non-object in C:\wamp\www\magento\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 182 Commented Jun 2, 2014 at 9:40
  • @AjayKulkarni. I've changed a bit the code in the answer. You can try again.
    – Marius
    Commented Jun 2, 2014 at 11:37
  • @AjayKulkarni. If this solved your problem, accept the answer. Don't leave loose ends.
    – Marius
    Commented Jun 2, 2014 at 11:58

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