读书人

应用Mageneto API新增一个分类

发布时间: 2012-11-06 14:07:00 作者: rapoo

使用Mageneto API新增一个分类
在$MAGENTO_INSTALLED_DIR目录下建立add.php,内容如下:

<?php    // 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   $id = $category->getId();    //if update    if ($id) {      $category->load($id);    }    $general['name'] = "Cars";    $general['path'] = "1/2"; // 1/2 是该分类存放的路径,根据需要调整。    $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.    $general['image'] = "cars.jpg";    $category->addData($general);    try {        $category->save();        echo "Success! Id: ".$category->getId();    }    catch (Exception $e){        echo $e->getMessage();    }?>

读书人网 >编程

热点推荐