//$parentId is the category id of a category under which you want to want add new category.
$category = Mage::getModel('catalog/category');
$category->setName('name of new category')
->setIsActive(1) //activate your category
->setDisplayMode('PRODUCTS')
->setIsAnchor(1)
->setCustomDesignApply(1)
->setAttributeSetId($category->getDefaultAttributeSetId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
unset($category);
$category->setName('name of new category')
->setIsActive(1) //activate your category
->setDisplayMode('PRODUCTS')
->setIsAnchor(1)
->setCustomDesignApply(1)
->setAttributeSetId($category->getDefaultAttributeSetId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
unset($category);
That's all.. Enjoy.. :)
No comments:
Post a Comment