Magento Create Category Programmatically

Magento Create Category Programmatically :

You can create categories programmatically in Magento by Mage::getModel(‘catalog/category’) method which is used to initialize and create the category in Magento 1.9

Note : There should be a parent category to begin this process.

Magento Create Category Programmatically Syntax

This code can be placed inside any PHP file that calls Magento bootstrapper and will execute the functionality accordingly.

$mageFilename = 'app/Mage.php';
$parentId = '2';// this is id of parent category
    $category = Mage::getModel('catalog/category');
    $category->setName('category name');
    $category->setIsAnchor(1); //active anchor
    $parentCategory = Mage::getModel('catalog/category')->load($parentId);

Using this code one can easily create 50+ categories in Magento programmatically. You can add category title and URL key to show in the front-end respectively.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *