Saturday, January 14

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
}

No comments:

Post a Comment

10 Best Chatting Apps In India

  The modern world is all about Internet. There was a time when people use to pay high telephone bills to stay in touch with their friends a...