How to add attributes to product grid or list view in category in Magento Commerce
There is actually a post on the Magento wiki that addresses how to add attributes to product grid or list view in category in Magento Commerce, but when we tried to do it, we came up with no results. After trying many different methods resulting in either no results or Magento error messages, we finally came up with this solution.
- First create your new attribute field in Magento Admin.
- Note what you name the new attribute field “code”. In our case, the attribute is names “freeshipping”.
- When you define this in the code side of Magento in the following steps, keep in mind you have to call it up with each word being capatalized, in this case it would be “FreeShipping”. (Don’t use the quotation marks I added unless you see them in the example code.)
- Open app/design/frontend/default/yourtheme/layout/catalog.xml
- Find the line that reads: <block type=”catalog/category_view” name=”category.products” template=”catalog/category/view.phtml”><block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”><block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
- Change it to read something like this:<block type=”catalog/category_view” name=”category.products” template=”catalog/category/view.phtml”><block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”><!–I added–><action method=”addAttribute”><name>FreeShipping</name></action><block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
- Next find the line in the same file that reads: <block type=”catalog/category_view” name=”category.products” template=”catalog/category/view.phtml”><block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”><block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
- Change it to read something like:<block type=”catalog/category_view” name=”category.products” template=”catalog/category/view.phtml”><block type=”catalog/product_list” name=”product_list” template=”catalog/product/list.phtml”><!–kj added–><action method=”addAttribute”><name>FreeShipping</name></action><block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
- Save the file.
- Open app/design/frontend/default/yourtheme/template/catalog/product/list.phtml
- Insert a line of code like this where you want it to appear: <p><h4> <?php echo ($_product->getFreeshipping()) ?></h4></p><p><h4 class=”product-free-ship”> <?php echo ($_product->getFreeshipping()) ?></h4></p>
- You’ll need to do this twice, once for “List View” and once for “Grid View”
- Save the file.
- Refresh your Magento Cache. You should now see your new entries including your Magento attributes.
