Add dropdown list of Manufactures (or another attribute)

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

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);
  9.      
  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="/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. 1.2.0.2 In the future some improvement to this hack.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs