Reputation: 53
I want to show a Category with its Products on homepage. Magento has built in option to show New Products on homepage and I have no idea about how to show different categories on homepage. For example I have created a category and I want to show the products in this category on homepage as below:
Product1 Product2 Product3
I have tried below code (from previous posts)
{{block type="catalog/product_new" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}
But this gives me below error
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
Apparently code I mentioned above is for previous versions or Magento. However version 1.9.0.1 gives error.
Please guide how to show categories on homepage. Thanks
Upvotes: 1
Views: 17379
Reputation: 7884
I have a below error: 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 183
find this code
<?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; ?>
replace code with
<?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;
?>
Upvotes: 0
Reputation: 5211
for new product list in magento 1.9 use this one
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}
or category wise listing
The new RWD design has two child blocks for the product list.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" />
You can first call your block in CMS Homepage like below:
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="4" template="catalog/product/list.phtml"}}
Now in your catalog/product/list.phtml find line no 74: and 133
find this code
<?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; ?>
replace with
<?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;
?>
go line no 188
add code into
if($this->getChild('after')):
//code
endif;
Upvotes: 2