Magento Fatal error: Call to a member function getSortedChildren() on a non-object

雨燕双飞 提交于 2019-12-23 10:09:54

问题


I have installed Magento CE 1.9 version and getting error after calling Catalog on Home page. Issue seems to be related with list.phtml.

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

I didn't change anything after installation and it seems this issue came with Magento 1.9 edition.

Issue is occurring for both List and Grid view on Catalog page as it is being called for both views.

Is there any best solution to resolve this issue ?


回答1:


you just have to delete the method ->getSortedChildren(); at line 134

$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();

so you have

$_nameAfterChildren = $this->getChild('name.after');



回答2:


Add these lines in your block section layouts file

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



回答3:


Replace the code by:

<?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; ?>

As seen in: https://magento.stackexchange.com/questions/20984/show-products-on-homepage-magento-1-9/20996#20996?newreg=c5c83466c28d45259ed36642cfe0a382




回答4:


The solution of Pass TeT will throw the PHP Error "PHP Fatal error: Can't use method return value in write context" because PHP doesn't have concept of emptyness. It's better to use <?php if($this->getChild('name.after')): ?> what wouldn't throw an error.




回答5:


Edit this file app/design/frontend/rwd/default/template/catalog/product/list.phtml Add this code at 73 and 135 lines

                <?php if(!empty($nameAfter = $this->getChild('name.after'))): ?>

just before:

                    $_nameAfterChildren = $nameAfter->getSortedChildren();

and add this code at 82 and 144 line

                <?php endif; ?>

right after

                <?php endforeach; ?>



回答6:


Hey guys I had the same problem - but it was because I hadn't copied all the files from app/default/default
to
app/yourTheme/default

I was missing files in the default directory. From my understanding - all files need to be copied.
/etc
/layout
/local
/template



来源:https://stackoverflow.com/questions/23654118/magento-fatal-error-call-to-a-member-function-getsortedchildren-on-a-non-obje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!