Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created March 12, 2017 16:52
Show Gist options
  • Save rintoug/bf0ba6f740501418ac6ac668b7b16f07 to your computer and use it in GitHub Desktop.
Save rintoug/bf0ba6f740501418ac6ac668b7b16f07 to your computer and use it in GitHub Desktop.
Magento create category programmatically
function createCategory(){
$parentId = 1;// Any of your parent category
$category = Mage::getModel('catalog/category');
$category->setName('My First Category');
$category->setUrlKey('My-First-Category');
$category->setIsActive(1); // to make active
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor(1); // This is for active anchor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment