I have a need to import magento categories with the following fields.

Note. I want to import even the category Ids coz I need them as they are. Do want to have new ones on import.

enter image description here

How do I do this using a script?

Or it there any extension that can handle this?

Thanks in advance

1 Answer 1


First you need to get the csv file where you add into folder directory

$uri = "myfile.csv";

The below code used to read the csv file content where $uri is the path of you csv file. $count is used to get teh file data for initials to last element block.

$mydata = array();
            if (($handle = fopen($uri, "r")) !== FALSE) 
                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
                            $mydata['id'][] =$data[0]; // id of category array
                            $mydata['name'][] =$data[1];// name array
                           // and add array as you like field in csv file.

the output of above code will make a array of 'id' and 'name' associated with the array unique key.

foreach($mydata['id'] as $key=>$catdata)
echo $name = $mydata['name'][$key];
//you can get the name of category associate with the key field

// to add the category in magento here you go 

$category = Mage::getModel('catalog/category');
                                                  $categoryName =  $name;
                                                  $rootCategory['name'] = $categoryName;
                                                  $rootCategory['path'] = "1/2"; 
                                                  //$rootCategory['display_mode'] = "PRODUCTS";
                                                  $rootCategory['is_active'] = 1;

                                                    $CategoryId = $category->getId();
                                                  catch (Exception $e)
                                                    echo "categories not found";


I hope this post will help you : thankyou

  • this did not work
    – Stifboy
    Jun 4, 2014 at 12:20

Your Answer

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

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