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

StackOverflow https://stackoverflow.com/questions/23654118

  •  22-07-2023
  •  | 
  •  

Pergunta

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 ?

Foi útil?

Solução

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');

Outras dicas

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"/>

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

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.

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

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top