The homepage of your website plays a vital role in your business. Online Shoppers will understand your homepage first before they choose to shop, so your business is to create the homepage engaging to the customer.
If not, they will leave your site instantly. One of the best ways to attract users by inserting your primary or trending products on the home page. So there is a huge chance of getting more buyers.
Lets learn how to add products in Magento of your websites homepage
Create a Featured Attribute in Magento Backend first Create an attribute featured with yes/no property from Catalog Input Type for Store Owner drop-down, then include it in attribute set and assign one product as Featured “yes” from Catalog->Manage Products.
Create a Custom Module
Create custom module and block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php” with following code in it.
class FeaturedProduct_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_List { protected $_productCollection; public function fetchProducts() { $this->productCollection =Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addFieldToFilter('featured_products', array('eq' => '1')); return $this->productCollection; } }
Create a configuration file in app/code/local/FeaturedProduct/Catalog/etc/config.xml
You have to specify a configuration file to tell magento about which XML is going to declare the block need to display featured products in homepage and which is located in app/code/local/FeaturedProduct/Catalog/etc/config.xml as:
FeaturedProduct_Catalog_Block featuredproduct.xml
Create view file “app/design/frontend/mytheme/default/template/catalog/product/featured.phtml” with following code in it :
fetchProducts();
$_helper = $this->helper('catalog/output');
?>
count()): ?>__('There are no products in the featured product list!!') ?>
productAttribute($_product, $_product->getName(), ‘name’) ?>
getRatingSummary()): ?> getReviewsSummaryHtml($_product, ‘short’) ?> getPriceHtml($_product, true) ?> isSaleable()): ?>
__(‘Out of stock’) ?>
That’s it.
Prefer to choose Installer Script for creating featured attribute mentioned in the beginning.
I hope you understood on How to add featured product in home page in Magento.
Try it