0

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.

2 Answers 2

0

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.

1
0

Hey guys I got my mistake.

$category->setStoreId(0); // <-- I was giving this Store ID wrong.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.