One of the first things you will notice when upgrading your Magento store to the recent 1.9.x versions is that products you had in static blocks on your homepage will be gone. You will likely get the following error:
Fatal error: Call to a member function getSortedChildren() on a non-object in ..../magento/app/design/frontend/rwd/default/template/catalog/product/list.phtml on line 180
The problem is that you will most likely try to display your products in the “old” Magento way like this:
<div class="page-title"> <h2>Latest Products</h2> </div> <p>{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}</p>
The reason why this doesn’t work anymore in Magento 1.9 is that the default RWD theme/design has two child blocks for the product list. These are:
<block type="core/text_list" name="product_list.name.after" as="name.after" /> <block type="core/text_list" name="product_list.after" as="after" />
The template itself has no checks to see if they are actually present before they are attempted to be loaded and used. You can fix this issue very quickly by simply using a different template that is a copy of the main template but with some fixes built in to it like this:
<?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; ?>
The name.after occurs twice in the template but the after occurs only once. One final thing to note down is that the default RWD css template hides the actions section of the product list on the cms pages. We hope that this solution has helped you to show products on your Magento 1.9 homepage. If you have any questions you can ask them in the comments below and we will answer them quickly for you.
The post How to show Products on Homepage in Magento 1.9 appeared first on Coding Basics.