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'.
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.
The brands are set up in two ways:
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.
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.
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:
// Navigation.php code
// render children
$htmlChildren = '';
$j = 0;
foreach ($activeChildren as $child) {
$htmlChildren .= $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
($j == $activeChildrenCount - 1),
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
$j++;
}
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '<div class="' . $childrenWrapClass . '">';
}
$html[] = '<ul class="level' . $level . '">';
$html[] = $htmlChildren;
// My modifications start here
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'brands');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
$html[] = '<ol id="nav-drop-brands">';
foreach ($manufacturers as $manufacturer) {
$html[] = '<li><a href="http://www.domain.com/catalogsearch/advanced/result?manufacturer[]=';
$html[] = $manufacturer['value'];
$html[] = '">';
$html[] = $manufacturer['label'];
$html[] = '</a></li>';
}
$html[] = '</ol>';
// end of my modifications
$html[] = '</ul>';
if ($childrenWrapClass) {
$html[] = '</div>';
}
}
$html[] = '</li>';
$html = implode("
", $html);
return $html;
}