【问题标题】:Show a CATEGORY and its products on Homepage, Magento1.9在主页上显示一个类别及其产品,Magento1.9
【发布时间】:2014-06-04 23:03:58
【问题描述】:

我想在主页上显示一个类别及其产品。 Magento 内置了在主页上显示新产品的选项,我不知道如何在主页上显示不同的类别。例如,我创建了一个类别,我想在主页上显示该类别中的产品,如下所示:

特色产品

产品1 产品2 产品3

我已经尝试过以下代码(来自以前的帖子)

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

但这给了我以下错误

Fatal error: Call to a member function getSortedChildren() on a non-object in C:\wamp\www\magento1901\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 134

显然我上面提到的代码是针对以前版本或 Magento 的。但是版本 1.9.0.1 给出了错误。

请指导如何在主页上显示类别。谢谢

【问题讨论】:

  • Kaiser,我已经在链接stackoverflow.com/questions/21241181/… 中解释了此类任务
  • 嗨,阿米特,您以前的帖子对我没有帮助。请您再次检查我编辑的问题并建议我该怎么做。
  • 嗨,凯撒,这已修复

标签: magento product


【解决方案1】:

对于 magento 1.9 中的新产品列表,请使用这个

   {{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

或分类列表

新的 RWD 设计有两个用于产品列表的子块。more info

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

您可以先在 CMS 主页中调用您的块,如下所示:

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

现在在您的目录/产品/list.phtml 中找到第 74 行:和第 133 行

找到这个代码

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

替换为

<?php
if($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; 
endif;
?>

去188号线

添加代码

if($this->getChild('after')):

//code

endif;

【讨论】:

  • 嗨 Ravi 我已经尝试过上述方法。它确实在主页上显示该类别的产品,但主页滑块和其他产品已经消失,我有以下错误:致命错误:在 C:\wamp\www\magento1901 中的非对象上调用成员函数 getSortedChildren() \app\design\frontend\rwd\default\template\catalog\product\list.phtml 在第 183 行
  • 检查你的情况,我可以在我的回答中添加。
【解决方案2】:

我有以下错误:致命错误:在 C:\wamp\www\magento1901\app\design\frontend\rwd\default\template\catalog\product 中的非对象上调用成员函数 getSortedChildren() ​\list.phtml 第 183 行

找到这个代码

<?php 
 //set product collection on after blocks
 $_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
if($this->getChild('after')):
//set product collection on after blocks
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach($_afterChildren as $_afterChildName):
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
$_afterChild->setProductCollection($_productCollection);
?>
<?php echo $_afterChild->toHtml(); ?>
<?php endforeach;
endif;
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多