【购物商城】鑫方盛初始化分类改为一、二、四级

栏目:云星瀚知识作者:金蝶来源:金蝶云社区发布:2024-09-22浏览:1

【购物商城】鑫方盛初始化分类改为一、二、四级

需求:鑫方盛一共有四级分类,购物商城默认只支持三级,目前鑫方盛分类初始化默认是导入鑫方盛的二、三、四级,客户想要导入鑫方盛的一、二、四级


二开指南:

修改集成管理-集成对象 SRM_XFS_GOODS_getChnCategory_init  的结果转换脚本


将里面的内容替换成一下内容保存

if ($result.success == false) {
	throw $result;
}
var result = [];
var fourth = $result.result;

for (value: fourth) {
	var param = {
		"code": value.code
	};
	//获取鑫方盛四级分类信息作为我们的三级叶子分类
	var fourthCategoryInfo = judgeSuccessAndTryAngain($service("/product/getCategoryInfo", param), $service, param);
	//如果分类已存在就不需要再取获取
	if (!Collection.contains(result, fourthCategoryInfo.parentCode)) {
		//获取鑫方盛三级级分类信息
		param = {
			"code": fourthCategoryInfo.parentCode
		};

		var thirdCategoryInfo = judgeSuccessAndTryAngain($service("/product/getCategoryInfo", param), $service, param);
  			result += {
		catId: fourthCategoryInfo.code,
		parentId: thirdCategoryInfo.parentCode,
		name: fourthCategoryInfo.name,
		catClass: fourthCategoryInfo.level - 1,
		state: fourthCategoryInfo.state,
		isleaf: "1"
			};
  		if (!Collection.contains(result, thirdCategoryInfo.parentCode)) {
            //获取鑫方盛二级级分类信息作为我们的二级分类
			param = {
				"code": thirdCategoryInfo.parentCode
			};
            var secondCategoryInfo = judgeSuccessAndTryAngain($service("/product/getCategoryInfo", param), $service, param);
        	result += {
			catId: secondCategoryInfo.code,
			parentId: secondCategoryInfo.parentCode,
			name: secondCategoryInfo.name,
			catClass: secondCategoryInfo.level,
			state: secondCategoryInfo.state,
			isleaf: "0"
		};
		//如果分类已存在就不需要再取获取
		if (!Collection.contains(result, secondCategoryInfo.parentCode)) {
			//获取鑫方盛一级分类信息作为我们的一级分类
			param = {
				"code": secondCategoryInfo.parentCode
			};

			var firstCategoryInfo = judgeSuccessAndTryAngain($service("/product/getCategoryInfo", param), $service, param);
			result += {
				catId: firstCategoryInfo.code,
				parentId: firstCategoryInfo.parentCode,
				name: firstCategoryInfo.name,
				catClass: firstCategoryInfo.level,
				state: firstCategoryInfo.state,
				isleaf: "0"
			};
		}
        }

	}

}
return result;

function judgeSuccessAndTryAngain(result, $service, param) {
	if (result.success) {
		return result.result;
	} else {
		if (result.resultMessage == "请求频繁,请稍后再试!") {
			Sleep(800);
			result = $service("/product/getCategoryInfo", param);
			if (result.success) {
				return result.result;
			} else {
				throw result;
			}
		}
		throw result;
	}
}


修改集成管理-集成对象 SRM_XFS_GOODS_getCategory_init  的结果转换脚本


将里面内容替换成以下内容

$result = judgeSuccessAndTryAngain($result,$service,param);
//test
//$result = [{"code":"03","parentCode":"0","name":"办公","level":1 ,"state":1 }];
//test
var firstcategory =$params.firstcategory;
var first = $result.filter(code==#.firstcategory).each({catId:code,parentId:"0",name:name,catClass:level,state:state,isleaf:"0"});
var result = [];
var second = [];
var third = [];
var fourth = [];
result = Collection.addAll(first, result);
for(value : first){
   second =Collection.addAll(second, getSecond($service,value));
}
result = Collection.addAll(second, result);

for(value : second){
  third =Collection.addAll(third, getThird($service,value));
}
//result = Collection.addAll(third, result);

for(value : third){
  fourth = Collection.addAll(fourth, getFourth($service,value));
}

$result = Collection.addAll(fourth, result);
var index = $result.length;
return Streaming({
  var item = $result[--index];
   if(item){
    return item;
  }else{
    return null;
  }
});

function getSecond($service,val){
  var param={"parentCode":val.catId};
 // Sleep(500);
  var res = judgeSuccessAndTryAngain($service("/product/getCategory",param),$service,param);
  return res.each({catId:code,parentId:parentCode,name:name,catClass:level,state:state,isleaf:"0"});
}

function getThird($service,val){
  var param={"parentCode":val.catId};
  //Sleep(500);
  var res = judgeSuccessAndTryAngain($service("/product/getCategory",param),$service,param);
  return res.each({catId:code,parentId:parentCode,name:name,catClass:level,state:state,isleaf:"0"});
}

function getFourth($service,val){
  var param={"parentCode":val.catId};
  //Sleep(500);
  var res = judgeSuccessAndTryAngain($service("/product/getCategory",param),$service,param);
  var data = res.each({catId:code,parentId:parentCode,name:name,catClass:level-1,state:state,isleaf:"1"});
  for(var i = 0; i < data.length; i++) {
    var fourthres = data[i];
	fourthres["parentId"] = val.parentId;
  }
  var data = data.filter($.catClass == 3);
  return data;
}

function judgeSuccessAndTryAngain(result,$service,param){
  if(result.success){
	 return result.result;
  }else{
    if(result.resultMessage == "请求频繁,请稍后再试!"){
      Sleep(800);
      result = $service("/product/getCategory",param);
      if(result.success){
      	return result.result;  
      }else{
        throw result;
      }
    }
    throw result;
  }
}


注意:替换后,已有鑫方盛分类不会替换或删除,请先手工或数据库删除。数据清除,以及上述集成对象修改后可直接重新执行服务流程 SRM_XFS_CHN_CATEGORY_INIT(鑫方盛xfs为第三方电商指定的商品池列表初始化)进行整体初始化,或者 SRM_XFS_CATEGORY_UPDATE (鑫方盛商品分类更新)指定某一级分类进行更新


注意:若重新在 商品管理-电商授权 进行开通初始化,需先在 开发平台-电商初始化配置 里把 鑫方盛商城初始化配置 里的 集成方案导入 给禁用,不然会覆盖以上修改集成对象,导致又再次引入二、三、四级鑫方盛

【购物商城】鑫方盛初始化分类改为一、二、四级

需求:鑫方盛一共有四级分类,购物商城默认只支持三级,目前鑫方盛分类初始化默认是导入鑫方盛的二、三、四级,客户想要导入鑫方盛的一、二...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息