Magento Navigation, how to customize very helpful information?

Magento Navigation, how to customize very helpful information?

This post describes how Magento navigation works. I hope it will help you.
The begining of all is in template file: “category/navigation/top.phtml”

<ul id="nav">
        < ?php
        foreach ($this->getStoreCategories() as $_category): ?>
            < ?php
            echo $this->drawItem($_category);
            ?>
        < ?php endforeach ?>
</ul>

There we call the method from class Mage_Catalog_Block_Navigation $this->getStoreCategories(). This method returns the array $_nodes from object Varien_Data_Tree_Node_Collection.

This array contains objects of Varien_Data_Tree_Node.
Every node is object of Varien_Data_Tree_Node and it is extension from Varien_Object.

Example 1:

If we wish to see how much categories we have, we can do it with method showed below:

< ?php
echo $this->getStoreCategories()->count();
?>

We will get only number of categories from the first level.

Example 2: (only level 1):

< ?php
foreach ($this->getStoreCategories() as $categories)
{
// $categories is object Varien_Data_Tree_Node extendec Varien_Object

echo $categories->getData('entity_id')."\n";
echo $categories->getData('parent_id')."\n";
echo $categories->getData('level')."\n";
echo $categories->getData('children_count')."\n";
}
?>

Every Varien_Data_Tree_Node contains varible $_childNodes

/**
     * Child nodes
     *
     * @var Varien_Data_Tree_Node_Collection
     */
    protected $_childNodes;
**/

and $_childNodes is instance of Varien_Data_Tree_Node_Collection.

Varien_Data_Tree_Node_Collection contains variable $_nodes which is array with Varian_Data_Tree_Node.

All this “revolves” through recursion …

8
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Domagoj Potkoc

Senior ZEND Developer

Domagoj Potkoc is part of "boiler room" together with Ivan Weiler, Hrvoje and Vanja. His special expertise are payment gateways.

Other posts from this author

Discussion 8 Comments

Add Comment
  1. Toni Anicic

    BTW. This is the first post of our new employee Domagoj Potkoc, so you guys might wish him a worm welcome here :)

  2. Domagoj,

    Hope to see more posts from you with magento as topic!

    Welcome to my world :)

    Regards,
    R

  3. Todd

    Welcome Domagoj!

  4. Welcome Dom to the WORLD OF TOMORROOOOWW!
    and the love hate relationship that Magento will quickly create :o )

  5. Ben

    Welcome to the party! Inchoo is like the Plava boja Žir of Croatia, so you should be happy… ;-)

    (I have no idea if that’s right. I hope I didn’t just insult 4.5M people.)

  6. Toni Anicic

    @Ben: it means something like “blue acorn” so I guess it’s what you’ve aimed for :)

  7. Animesh sheolikar

    very good post .saved lot of time thanks.:)

  8. How can I move the navigation to the header.html file? I get errors when I just copy and paste the code from Top.html.

    Thanks

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top