在主页上显示产品magento 1.9


23

刚安装了magento 1.9并已陷入第一个障碍。我已经创建了一个产品,并使用了先前版本中的建议在首页上显示了该产品,但收到了以下消息

致命错误:在第180行getSortedChildren()上的非对象app/design/frontend/rwd/default/template/catalog/product/list.phtml上调用成员函数

非常感谢任何帮助。

在首页的内容部分,我有...

<div class="page-title"> 
    <h2>Our Latest Products</h2> 
</div> 
<p>{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}</p>

您可以使用添加产品时使用的代码来更新您的答案吗?
— 桑德·曼格尔

嗨,我使用的版本与第8版相同。在首页的内容部分中,我有... <div class =“ page-title”> <h2>我们的最新产品</ h2> </ div> < p> {{block type =“ catalog / product_list” category_id =“ 3” template =“ catalog / product / list.phtml”}} </ p>
— rufus

Answers:


24

问题在于新的rwd设计在产品列表中有两个子块:

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

并且在模板本身中,在尝试加载和使用它们之前不会检查它们是否存在。

一个快速的解决方案是使用一个不同的模板,该模板是主模板的副本,但具有以下修改:

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

该name.after模板中出现两次,但after似乎只有一个。最后要注意的一件事是,默认的rwd css在cms页面上隐藏了产品列表的action部分。


您能指出在rwd主题中必须将此代码添加到哪个文件中吗?
— 巴尔加夫·梅塔2015年

添加什么文件以及行会有所帮助。上面的代码与list.phtml中的代码不匹配
— Philip Deatherage 2015年

philip,您好,这可能是magento的最新版本已解决此问题。
— David Manners,2015年

需要复制哪个主模板?list.phtml?
— Pixelomo
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.