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?

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 } ?>
  • 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. – brainReader Jun 2 '14 at 9:36
  • @AjayKulkarni. I've re-taged your question. – Marius Jun 2 '14 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 – brainReader Jun 2 '14 at 9:40
  • @AjayKulkarni. I've changed a bit the code in the answer. You can try again. – Marius Jun 2 '14 at 11:37
  • @AjayKulkarni. If this solved your problem, accept the answer. Don't leave loose ends. – Marius Jun 2 '14 at 11:58

protected by Community Sep 10 '14 at 11:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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