This tutorial will show you how to implement a Featured Product feature. The Featured Product is a product with an attribute added from the admin. When the administrator selects “Yes” in the “Featured” attribute, that product will be displayed in a content block on the category page.
I’ll explain each step I took to make this custom feature. Please forgive me if I left anything out.
Step 1) Create new "Featured" attribute |
Create a new attribute by going to Catalog > Attributes > Manage Attributes > Add New Attribute.
Attribute Properties
Front End Properties
Manage Label/Options
Save the new attribute and go to Catalog → Attributes → Manage Attributes Sets to add the attribute to the default feature set.
Step 2) Add Block configuration to catalog.xml |
Open MyCompany/app/design/frontend/default/default/layout/catalog.xml. We want to add a new <block> right above the product list block in the default category layout.
Insert the block configuration on line 73 (default catalog.xml).
Step 3) Create new block class that will instantiate the featured product |
Create a new file, and directories: app/code/local/MyCompany/Catalog/Block/Product/Featured.php
We’re almost there!
Step 4) Extend Mage_Catalog_Block_Category_View |
Create a new file, and directories, called app/code/local/MyCompany/Catalog/Block/Category/View.php. We’re extending the core class here so our module will be separate from the core code base. When upgrading, we won’t have to worry about our code not working or having to patch files.
Step 5) Modify the templates |
I haven’t really integrated any real HTML changes, so I will simply point out the files to create and where to edit the HTML.
Edit app/design/frontend/default/default/template/catalog/category/view.phtml and add the following code:
right above this line:
Edit app/design/frontend/default/default/template/catalog/product/featured.phtml and customize your HTML here (see any of the product templates for Product object member variables).
Step 6) Add new blocks to the app/etc/local.xml |
Add the following inside the config global tag:
I hope this helps you add a “Featured Product” feature. It certainly feels thorough, but if I left anything out, please let me know and I’ll be happy to help.
Thanks,
Andy