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'); }
相关文章推荐
- sql批量插入:存在id相同则更新数据
- 新建一个分类的api ,Create new magento Rest api to get category list in magento
- 假设对testid有更新则插入一条新记录,那么怎么查询出testid最后的状态(分组查询)
- mysql插入时存在就更新
- mysql更新语句获取受影响行数和插入记录id
- SQL用户存在则更新不存在则插入
- 触发器在插入时更新此条新记录 错误it is already used by statement which invoked this stored functiontrigger的解决方法
- MySQL 判断记录是否存在,不存在则插入存在则更新
- mysql学习总结一当数据不存在的时候插入,存在的时候进行更新,删除重复数据
- MySql 不存在则插入,存在则更新或忽略
- sqlserver 自增ID插入指定数据
- MySQL记录存在则更新,不存在插入on duplicate key update
- voltdb 记录存在时候更新,不存在时候插入
- 数据库修改之更新员工表,根据ID删除Mapping表数据,再插入数据
- MySQL 当记录不存在时插入,当记录存在时更新
- 当表中数据不存在即插入,当存在时,即更新
- Mysql—实现批量插入,存在就更新,不存在就插入
- SSIS(SQL Server Integration Service)处理导入数据时, 存在的更新, 不存在的插入
- MySQL 当记录不存在时插入,当记录存在时更新
- Magento获取指定分类下的产品和获取子分类及产品数量