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 thins function: [code]public function getAllManu()

  {
    $product = Mage::getModel('catalog/product');
    $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
                ->setEntityTypeFilter($product->getResource()->getTypeId())
                ->addFieldToFilter('attribute_code', 'manufacturer'); //isto pode ser mudado para qualquer atributo
    $attribute = $attributes->getFirstItem()->setEntity($product->getResource());
    $manufacturers = $attribute->getSource()->getAllOptions(false);
    
    return $manufacturers;
  }[/code]

You can modify the name of variables or of the function 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:

[code]<select id=”select-manufacturer” onchange=”window.location.href=this.value”>

  <?php foreach ($this->getAllManu() as $manufacturer): ?>
      <option value="<?php Mage::getURL() ?>catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>"><?php echo $manufacturer['label'] ?></option>
  <?php endforeach; ?>
  </select>[/code]

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