您的位置:首页 > 编程语言 > Go语言

magento 分类指定id插入,id存在更新 - create category by category id

2014-04-03 14:26 323 查看
private function updateCategory($category_array){
Mage::register('isSecureArea', 1);
foreach($category_array as $category){
$id = $category->id;
$parent_id = $category->parent_id;
$name = $category->name;
$is_active = $category->is_active;
$level = $category1->level;
$url_key = $category->url_key;
$url = $category->url;
$position = $category->position;
$category_model = Mage::getModel('catalog/category')->load($id);
if(!$category_model->getId()){
$categoryID = $id;  //Your category ID
$categoryName = $name;  //Your category name
$parentCategory = Mage::getModel('catalog/category')->load($parent_id); //Your parent category's ID
//1st save with initial category information (inc. ID)
if($parentCategory->getId()){
$category = new Mage_Catalog_Model_Category();
$category->setName($categoryName);
$category->setId($categoryID);
$category->setPath($parentCategory->getPath()); //Shouldn't be needed here
$category->setIsActive(1);
$category->setPosition($position);
$category->save();
//2nd save with correct path underneath the parent category
$category->setPath($parentCategory->getPath() . '/' . $categoryID);
$category->save();
}
}else{
//$category_model->setName($name)->save();
$category_model->setParentId($parent_id)
->setName($name)
->setIsActive($is_active)
->setLevel($level)
->setUrlKey($url_key)
->setUrl($url)
->setPosition($position)
->save()
;
}
}
Mage::unregister('isSecureArea');
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: