How to Import Categories in Magento Using Script

categoryimportscript

Hello I have just started to learn magento. Now I was trying to import category in magento through script.

my magento code looks like

<?php
    require_once 'businessclasses.php';
    define('MAGENTO', realpath(dirname(__FILE__)));
    require_once MAGENTO . '/app/Mage.php';
    umask(0);
    $count = 0;

    echo "<pre>";
    $data= new getCSV();
    $rows=$data->getRootCategories(); // Gets the list of root categories.

    foreach($rows as $row) {
        echo $categoryName = $row['us']; // Name of Category

        // Create category object
        $category = Mage::getModel('catalog/category');
        $category->setStoreId(1); // 'US-Store' store is assigned to this category

        $rootCategory['name'] = $categoryName;
        $rootCategory['path'] = "1/23/25"; // this is the catgeory path
        $rootCategory['display_mode'] = "PRODUCTS";
        $rootCategory['is_active'] = 1;
        $rootCategory['is_anchor'] = 1;
        $rootCategory['thumbnail'] = $row['catimg'].'.jpg';
        $category->addData($rootCategory);

        try {
            $category->save();
            echo $rootCategoryId = $category->getId();
        }
        catch (Exception $e){
            echo $e->getMessage();
        }
    }
?>

Now the category is importing successfully but image is not setting up there. It is not displaying category image there.

Can anyone help? Thank you in advance.

Best Answer

I use something like URapidflow, its much easier and has all the functionality built in for importing, also Magmi is useful tool to check and its free.

Related Topic