1

How to create a navigation menu with brand(manufacturer) attribute? Is that possible?

4

There are basically 2 options for this.

1) You can loop through these options creating a list of links which you can place on a block that will be your menu. The links will be directed to the advanced search page*.

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'brand');
if ($attribute->usesSource()) {
    $options = $attribute->getSource()->getAllOptions(false);
    foreach ($options as $option)
    {
        echo '<a href="'.Mage::getUrl('catalogsearch/advanced/result', array('brand'=>$option['value'])).'">'.$option['label'].'</a>';
    }
}

Downside to this is that it takes hard coded values and the urls will be something like domain.com/allproducts?brand=5

2) A better option is to create categories for each brand and assign the products accordingly. This way the URL will be much better for SEO domain.com/brands/foobar-brand/ and it doesn't require any custom code as you are using basic Magento functionality.

This does however require the administrator to add a product to both a category and set the brand.

[EDIT] *thanks to @Marius for suggesting using the search page in option 1 instead of a category with all products

  • 1
    +1 for the first option, with just a small comment. You don't need to create a new category with all the products. You can just make the brand attribute 'Used in advanced search' and make the link Mage::getUrl('catalogsearch/advanced/result', array('brand'=>$option['value'])). So basically send the customer to the advanced search page with the selected brand. In my opinion is easier to manage it like that than to have an additional category for each brand. – Marius Jan 9 '14 at 10:04
  • Perfect! I'll use it in my answer if you don't mind... and the project I'm working on right now ;) – Sander Mangel Jan 9 '14 at 10:11
  • My answer is under the WTFPL license en.wikipedia.org/wiki/WTFPL so ... your call :) – Marius Jan 9 '14 at 10:13
  • Hahaha wow didn't even know that existed – Sander Mangel Jan 9 '14 at 10:14
0

Based on Sander's great answer above, using option #1, which didn't work for me on 1.9+, so I modified code a bit:

<li>
 <a href="#">Browse by Manufacturer</a>
 <ul>
<?php $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'manufacturer');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $option)
{
    echo '<li style="list-style:none"><a href="'.Mage::getUrl('catalogsearch/advanced/result').'?manufacturer%5B%5D='.$option['value'].'">'.$option['label'].'</a></li>';
}
} ?>
 </ul>
</li>
0

Change the option value to a sub category of main category is wasting the resource. My 'shop by brand' module on www.epacificweb.com does not waste the resource. But convert it to M2 is tough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.