title: Magento add brands list inside category drop down menu
body: <p>I am trying to add a listing of brands inside each category drop down list from the main menu. I believe this would be considered as a 'mega menu'.</p>
  
  <p>For example - if i hover over a main category it will not only show sub categories in the drop down menu, but also all the different brands inside this category.</p>
  
  <p>The brands are set up in two ways:</p>
  
  <ol>
  <li><p>All products have an attribute 'brand'. Therefore we could try to get all the products inside the category and display a list of all the brands associated with the products in this category. This would need to incorporate layered navigation so that when that menu item is selected, it will show a filter of items from that category AND that brand attribute.</p></li>
  <li><p>I think this method would be easier - Each brand already has it's own category created as well, and each product is in both the main category, as well as it's relevant brand category. This was originally done so we could show a big listing of all brands. Is there function in Magento inside the navigation loop to get 'other chosen categories'? E.g. If an item is in Category A, the drop down list shows all sub-categories, but also any other related top level categories which are selected on the products. </p></li>
  </ol>
  
  <p>I have tried various solutions which involved modifying Navigation.php (magento 1.6) but I could only get it to display ALL brands in the shop, not just brands inside a particular category. See code below:</p>
  
  <pre><code>// Navigation.php code
  // render children
      $htmlChildren = '';
      $j = 0;
      foreach ($activeChildren as $child) {
      $htmlChildren .= $this-&gt;_renderCategoryMenuItemHtml(
      $child,
      ($level + 1),
      ($j == $activeChildrenCount - 1),
      ($j == 0),
      false,
      $outermostItemClass,
      $childrenWrapClass,
      $noEventAttributes
      );
      $j++;
      }
      if (!empty($htmlChildren)) {
      if ($childrenWrapClass) {
      $html[] = '&lt;div class="' . $childrenWrapClass . '"&gt;';
      }
      $html[] = '&lt;ul class="level' . $level . '"&gt;';
      $html[] = $htmlChildren;
  
      // My modifications start here
  
      $product = Mage::getModel('catalog/product');
      $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
      -&gt;setEntityTypeFilter($product-&gt;getResource()-&gt;getTypeId())
      -&gt;addFieldToFilter('attribute_code', 'brands');
      $attribute = $attributes-&gt;getFirstItem()-&gt;setEntity($product-&gt;getResource());
      $manufacturers = $attribute-&gt;getSource()-&gt;getAllOptions(false);
      $html[] = '&lt;ol id="nav-drop-brands"&gt;';
      foreach ($manufacturers as $manufacturer) {
      $html[] = '&lt;li&gt;&lt;a href="http://www.domain.com/catalogsearch/advanced/result?manufacturer[]=';
      $html[] = $manufacturer['value'];
      $html[] = '"&gt;';
      $html[] = $manufacturer['label'];
      $html[] = '&lt;/a&gt;&lt;/li&gt;';
      }
      $html[] = '&lt;/ol&gt;';
  
      // end of my modifications 
  
      $html[] = '&lt;/ul&gt;';
      if ($childrenWrapClass) {
      $html[] = '&lt;/div&gt;';
      }
      }
  
      $html[] = '&lt;/li&gt;';
  
      $html = implode("\n", $html);
      return $html;
      }
  </code></pre>