Solving Homepage Featured Products Listing in Magento 1.9
If you’re struggling to implement a featured products list on your Magento 1.9 homepage, don’t worryâyou’re not alone! Many resources out there are outdated or fail in the latest versions of this platform. In this guide, we’ll walk through a step-by-step solution that works perfectly for Magento 1.9.
Understanding the Problem
The issue lies primarily with the way content is managed on the CMS homepage in Magento 1.9. Unlike earlier versions, you can’t simply insert blocks or widgets directly into the page layout. Instead, you’ll need to create a custom module and integrate it using templates and layouts.
Step 1: Create a New Module
First, let’s create a new local module called HomepageFeaturedProducts. Navigate to your Magento installation directory and run the following command in the terminal:
mkdir -p app/code/local/HomepageFeaturedProducts
Then, create the necessary files for this module:
app/code/local/HomepageFeaturedProducts/etc/config.xml
app/code/local/HomepageFeaturedProducts/Block/Featuredproducts.php
app/code/local/HomepageFeaturedProducts/template/cms/page/homepage.phtml
app/design/frontend/default/<YOUR_THEME>/template/cms/page/homepage.phtml
Replace <YOUR_THEME> with your actual theme name.
Step 2: Configure the Module
Open config.xml and add the following content:
<?xml version="1.0"?>
<config>
<modules>
<HomepageFeaturedProducts>
<active>true</active>
<codePool>local</codePool>
</HomepageFeaturedProducts>
</modules>
</config>
Step 3: Create the Featured Products Block
In app/code/local/HomepageFeaturedProducts/Block/Featuredproducts.php, define your block class:
class HomepageFeaturedProducts_Block_Featuredproducts extends Mage_Core_Block_Template {
public function getFeaturedProducts() {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect(array('sku', 'name', 'short_description'))
->addFieldToFilter('visibility', array('eq' => 2))
->setCurPage(1)
->setPageSize(3); // Change this to the number of products you want
return $collection;
}
}
Step 4: Modify the CMS Template
Open app/code/local/HomepageFeaturedProducts/template/cms/page/homepage.phtml and add the following code:
<?php
$featuredProductsBlock = $this->getLayout()->createBlock('homepagefeaturedproducts/featuredproducts')->setTemplate('homepage/featured_products.phtml');
echo $featuredProductsBlock->toHtml();
?>
Then, create a new file app/code/local/HomepageFeaturedProducts/template/homepage/featured_products.phtml and add your HTML template for the featured products.
Step 5: Update Your CMS Homepage
Finally, update your CMS homepage content to use this custom template. In the “Design” section, select “Custom design” and choose the new template we created earlier (homepage).
Save your changes, clear the cache if necessary, and reload your website’s homepage.
Conclusion
Implementing a featured products list on your Magento 1.9 homepage requires a bit more effort than in previous versions. However, by following these steps, you should have no trouble creating a clean, well-organized solution that showcases your top products perfectly.
If you need further assistance with custom module development or other Magento-related services, feel free to explore our comprehensive range of solutions at Laravel Company.
Happy coding!