Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

adding_a_new_category

Last modified by Bojan Hrnkas on Fri, May 9, 2008 15:04
Source|Old Revisions  

Ok, here is how you can add a category using Magento API:

// initialize magento environment for 'default' store
require_once 'app/Mage.php';
Mage::app('default');

//get a new category object
$category = Mage::getModel('catalog/category');
$category->setStoreId(0); //default/all

//if update
if ($id) {
  $category->load($id);
}

$general['name'] = "Cars";
$general['path'] = "1/3"; // 1/3 is root catalog
$general['description'] = "Great new cars";
$general['meta_title'] = "Cars"; //Page title
$general['meta_keywords'] = "car, automobile";
$general['meta_description'] = "Some description to be found by meta search robots.";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['url_key'] = "cars";//url to be used for this category's page by magento.


$category->addData($general);

try {
    $category->save();
    echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
    echo $e->getMessage();
}



 

Popular Wiki Tags  |  View all

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien