Create new categories using magento scripts

function addManufacturers( $manufacturers ) { Mage::register(‘isSecureArea’, 1); $parentId = ‘2’; $list = array(); foreach ($manufacturers as $key => $manufacturer) { try { $enabled = 1; if ($key == 0) { $parentId = ‘2’; } else { $parentId = $list[0]; } $category = Mage::getModel(‘catalog/category’); $category->setName($manufacturer); $category->setMetaTitle($manufacturer); $category->setIncludeInMenu(1); $category->setUrlKey(strtolower($manufacturer)); $category->setDescription(strip_tags($manufacturer)); $category->setMetaDescription($manufacturer); $category->setMetaKeywords($manufacturer); $category->setIsActive($enabled); $category->setDisplayMode(‘PRODUCTS’); $category->setIsAnchor(1); //for active… Read more »

function addManufacturers( $manufacturers ) {
    Mage::register('isSecureArea', 1);
    $parentId = '2';
    $list = array();

    foreach ($manufacturers as  $key => $manufacturer) {
        try {

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

            $category = Mage::getModel('catalog/category');
            $category->setName($manufacturer);
            $category->setMetaTitle($manufacturer);
            $category->setIncludeInMenu(1);
            $category->setUrlKey(strtolower($manufacturer));
            $category->setDescription(strip_tags($manufacturer));
            $category->setMetaDescription($manufacturer);
            $category->setMetaKeywords($manufacturer);
            $category->setIsActive($enabled);
            $category->setDisplayMode('PRODUCTS');
            $category->setIsAnchor(1); //for active anchor
            $category->setStoreId(Mage::app()->getStore()->getId());
            $parentCategory = Mage::getModel('catalog/category')->load($parentId);
            $category->setPath($parentCategory->getPath());
            $category->setCustomUseParentSettings(true);
            $category->save();
            $list[$key] = $category->getId();
            echo 'Category ' . $category->getName() . ' ' . $category->getId() . ' imported successfully' . PHP_EOL;
        } catch (Exception $e) {
            echo 'Something failed for category ' . $manufacturer . PHP_EOL;
            print_r($e);
        }
    }
    return $list;
}

Share this Tutorial