Magento – Magento attribute Menu

magento-1.7PHP

I don't know this is easy to you or not but i need help Please help me

I need a attributes menu in Magento which auto generate

Like admin add 3-4 color and 3-4 size of some product then top menu comes up automatically with 2 menus

1.Color 
2.Size 

And under this drop down user can see which type of color and size available on this store after clicking of any he will show these all products which having this attributes.

if admin add only one extra color/size for any one product this color/size should be on the drop down list.

Thank you I hope you can understand my Question

Best Answer

There is an explanation on how you can add menu items in the top menu in this question.
You can use the event page_block_html_topmenu_gethtml_before to add menu items to the top menu.
Your observer can look something like this:

public function addItemsToTopmenuItems($observer){
    //get the menu object: //Type Varien_Data_Tree_Node
    $menu = $observer->getMenu();
    //get the tree object in the menu //type Varien_Data_Tree
    $tree = $menu->getTree();
    //get current page handler
    $action = Mage::app()->getFrontController()->getAction()->getFullActionName();
    $colorNodeId = 'color';
    //set the node id, label and url
    $data = array(
        'name' => Mage::helper('catalog')->__('By Color'),
        'id' => $colorNodeId,
        'url' => '#', // no url because there is no page for color
    );
    //create a node object
    $colorNode = new Varien_Data_Tree_Node($data, 'id', $tree, $menu);

    //now create a node for each available color
    $colors = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color')->getSource()->getAllOptions();
    foreach ($colors as $color) {
         $nodeId = 'color-'.$color['value'];
         $data = array(
            'name' => $color['label'], // color label here
            'id' => $nodeId,
            'url' => Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'color='.$color['value'])), // use the advanced search url with a selected color to avoid creating a separate page.
         );
         $node = new Varien_Data_Tree_Node($data, 'id', $tree, $colorNode);
         $colorNode->addChild($node); //add node as submenu for the main color item
    }
    //add the color main node to the menu
    $menu->addChild($colorNode);
    return $this;
}

I haven't tested the code so you might get some errors, but the idea is the right one. Trust me :).