insert category programmatically in magento
In this post we’ll show you how to magento insert category programmatically using magento. By using following code we can insert category programmatically and this code also work in exteranl magen to file.
$parentId = '2'; // prenet catagory try{ $category = Mage::getModel('catalog/category'); $category->setName('category-name'); // category name //$category->setUrlKey('your-category-url-key'); // url key $category->setIsActive(1); // is active $category->setDisplayMode('PRODUCTS'); $category->setIsAnchor(1); //for active anchor $category->setStoreId(Mage::app()->getStore()->getId()); $_parent_category = Mage::getModel('catalog/category')->load($parentId); $category->setPath($_parent_category->getPath()); $cat_data= $category->save(); // insert catagory //echo $cat_data->getEntityId();// print catagory id } catch(Exception $e) { print_r($e);//Exception in insert catagory }
Hope this code and post will helped you for implement insert category programmatically in magento. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org