Add dropdown list of Manufactures (or another attribute)

Last modified by powerPT on Fri, June 25, 2010 09:11
Source|Old Revisions  

This is an old revision of the document!

First of all, take a look to attributes list, in admin panel. So, if you want to show some attribute in your store, it must be entered in the list AND searchable in advanced search. Look the image:

Then, edit app/code/core/Mage/Catalog/Block/Navigation.php

Go to the last line and add this function:

  1. public function getAllManu()
  2.     {
  3.       $product = Mage::getModel('catalog/product');
  4.       $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
  5.                   ->setEntityTypeFilter($product->getResource()->getTypeId())
  6.                   ->addFieldToFilter('attribute_code', 'manufacturer'); //can be changed to any attribute
  7.       $attribute = $attributes->getFirstItem()->setEntity($product->getResource());
  8.       $manufacturers = $attribute->getSource()->getAllOptions(false);
  10.       return $manufacturers;
  11.     }

You can modify the name of variables or the function name but be careful.

And now you select where put the list of manufactures, in your store. In my case I decided to put just right of categories list, in topmenu so, I edit app/design/frontend/default/default/template/catalog/navigation/top.phtml Above line 44 (</ul>) I add this code:

  1. <select id="select-manufacturer" onchange="window.location.href=this.value">
  2. <option value="#" selected="selected">--Select Manufacturer--</option>
  3.     <?php foreach ($this->getAllManu() as $manufacturer): ?>
  4.         <option value="<?php Mage::getURL() ?>catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>"><?php echo $manufacturer['label'] ?></option>
  5.     <?php endforeach; ?>
  6.     </select>

And just this. Works like a charm in Magento ver. In the future some improvement to this hack.