在主页Magento1.9上显示CATEGORY及其产品

时间:2014-06-04 23:03:59

标签: magento product

我想在主页上显示其产品类别。 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会出错。

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

2 个答案:

答案 0 :(得分:2)

  

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

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

enter image description here 或类别明智的列表

新的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"}}

现在在您的catalog / product / 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;

答案 1 :(得分:0)

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

找到这段代码

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