【问题标题】:Call to a member function getSortedChildren() on a non-object in magento 1.9在 magento 1.9 中对非对象调用成员函数 getSortedChildren()
【发布时间】:2017-04-06 19:33:20
【问题描述】:

我已经安装了 magento 1.9。我想在首页显示所有产品。

所以我在主页内容部分添加代码,

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}

但它显示 Call to a member function getSortedChildren() on a non-object in C:\xampp\htdocs\magento\app\design\frontend\rwd\default\template\catalog\product\list.phtml 在线74.

但是当我在主页添加新产品时它会正常工作。

我可以知道如何解决这个问题吗?

感谢您的帮助。

谢谢。

【问题讨论】:

  • 你对list.phtml做了什么修改吗?
  • @Shivanand,我检查了原始代码,发现这个错误可能!我有修复它,但我不知道是否可以编辑 magento 打包文件
  • 可以编辑包文件。但首先,如果它们是主题包文件,则需要将它们复制到您自己的主题包;如果它们是代码/核心文件,则需要将它们复制到代码/本地,具有相同的目录结构。

标签: php magento


【解决方案1】:

对 list.phtml 文件的简单编辑将修复此错误

这是文件位置

Magento/app/design/frontend/default/your_theme/template/catalog/product/

将第 73 行到第 80 行的 sn-p 更改为:

<?php
$_nameAfter = $this->getChild('name.after');
if(is_object($_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 ?>

关于如何自定义模板请参考这两篇维基文章:

希望对你有帮助

【讨论】:

    【解决方案2】:

    更改您的代码

    $_renderers = $this->getParentBlock()->getChild('state_renderers')->getSortedChildren();
    

    $_renderers = $this->getParentBlock()->getChild('state_renderers');
    

    这将解决您的问题

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 2015-06-16
      • 2016-02-02
      • 2014-05-06
      • 1970-01-01
      相关资源
      最近更新 更多