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

来源:互联网 发布:jquery json转object 编辑:程序博客网 时间:2024/06/14 07:48
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');}

0 0
原创粉丝点击