Home > Magento Tips > Find Magento Category IDs

Find Magento Category IDs

Posted on: 10th Jun 2010 By: Adam Moss 2 Comments

Picture the scene…. no I’m not about to describe a tropical paradise, but a fairly common situation that us Dataflow users have encountered on many occasions. You’ve got a shop with dozens, perhaps hundreds of categories on it and you’ve just exported your spreadsheet. You now realise that you need to know the IDs of all the categories in order to get any products that you add into the right category. So you go to the Magento admin, look at the category list and find that the only way to see the category ID is to click on each one. You then realise this is going to take forever. You then decide to give up and go and become a fisherman like you always dreamed, relaxing on a boat in the lake district… but that’s a different scene.

Before you go and grab your fishing hat, simply open Navigation.php from app > code > core > Mage > Catalog > Block > Navigation.php

Find this piece of code on line 221 and 289:

 $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";

And replace with this (the difference is the getId() part):

 $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).' ('.$this->htmlEscape($category->getId()).')</span></a>'."\n";

No more blindly fishing around for category IDs, you’ll find each one displayed nicely from your topMenu(); in brackets next to its corresponding name. This also means your store will temporarily have numbers all over it (until you remove it again), so I’d suggest you copy and paste the data onto a workbook, then you’re sorted.

Keep checking back at the Magento Blog at Ecommerce Website Design for more Magento tips, tutorials and advice – and also look out for the Magento Fox!

2 Responses to “ Find Magento Category IDs ”

  1. Tom
    #1 | 5th October 2010

    I’m currently struggling massively with a custom navigation.php file.

    Basically I’d like to set the top category name as the nav ul class or id – however I just can’t get it to work properly and it’s driving me insane!

    I know that I need to edit the following lines, but my php knowledge is obviously not good enough -

    $html .= ”;
    $i = 0;
    foreach ($chunks as $key=>$value) {
    $html .= ”;
    $html .= $this->drawNestedMenus($value, 1);
    $html .= ”;
    $i++;
    }
    $html .= ”;

    I have tried various bits of code, including:

    $html .= ‘htmlEscape($category->getName()).”>’;

    and

    $html .= ‘htmlEscape($category->getName()). ;
    $html .= ‘ “>’;

    Any help would be hugely appreciated

  2. Ravi
    #2 | 6th April 2011

    Very Good Article.

    Thanks

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.