Skip to content

Quickly find the id of all Magento categories..

When developing a Magento powered e-commerce, you will almost inevitably have to import product data from a spreadsheet provided by your customer. And you almost certainly will need to convert the text based Categories they’ve used in the spreadsheet into the entity_id Magento uses for categories. So first of all create all your required product categories. Then what? Yes, you can click into every category in the Magento admin and patiently write down every ID, but that’s boring right? So what to do?

Create a new .php file somewhere in the root folder and drop the following code in.

define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
$model = Mage::getModel('catalog/category');
$categories = $model->getCollection();
foreach ($categories as $category) {
    print $category->getEntityId() . " " . $category->getName() . PHP_EOL;
This entry was posted in Uncategorized. Bookmark the permalink.


Sorry, comments are closed on this page.