I'm still a Beginner in Magento and I was given a task to upload/create 600 Categories and have a hierarchy up to 4th subcategory. I've been searching for a while now, and most return paid extensions. Would someone be kind enough to help me perform this or point me to a guide? So far I have found a random script; it ran well with no errors yet still didn't create any category.

Thanks in advance

  • If you are not able to do this task, look for some one who teaches it to you. Magento offers great courses with awesome teachers ;-) Nov 25, 2013 at 7:59

6 Answers 6


I've created a script for this last weekend. It works on a simple text file and white spaces to indicate hierarchy. Just make sure the Root category exists and the name is correct.

Run the scripts from a subdirectory in your web root directory (the directory you've installed Magento in) preferably using SSH and not through a webbrowser.

This should take away most of your work.



Here is a nice extension (look for "Import/Export Magento Category Extension" in the page) that can import/export a tree of categories.
You have to build a csv file with your categories in a specific format (nothing fancy though) and place it in a folder of your magento instance, then run some actions in the admin.
I don't really like the fact that the source file must be placed on the disk , but with some small changes it can be changed to accept a file upload.


Creating categories is quite easy. Have a look on

\Mage_Catalog_Model_Category_Api_V2::create($parentId, $categoryData, $store = null)

So create a structure to create the categories in the right order

  • 1st level
  • 2nd level
  • etc.

Remember the ids and use them as $parentId.


This should be what you are looking for https://www.sonassi.com/knowledge-base/quick-script-batch-create-magento-categories/


I too just recently wrote a category import. The setPath() method was the key to my situation.

     $category = Mage::getModel('catalog/category')

Prior to that code I build each category a Path of category ids, starting with the base like so:

$catPath = '1/2';

Please refer my tutorial here I am explaining how to create category and subcategories using the magento script.


I am pasting some sample code here.The $import_category array contain the data.

foreach ($arrResult as $import_category) {
    try {
        if (strtolower($import_category[16]) == 'true') {
            $enabled = 1;
        } else {
            $enabled = 0;

        if ($import_category[1] == 0) {
            $parentId = '2';
        else {
            $parentId = $list[$import_category[1]];

        $category = Mage::getModel('catalog/category');
        $category->setIsAnchor(1); //for active anchor
        $parentCategory = Mage::getModel('catalog/category')->load($parentId);
        $list[$import_category[0]] = $category->getId();
        echo 'Category ' . $category->getName() . ' ' . $category->getId() . ' imported successfully' . PHP_EOL;
    } catch (Exception $e) {
        echo 'Something failed for category ' . $import_category[2] . PHP_EOL;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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