//start at level 0 of categories
for (GenericValue catalogCategory : catalogCategories) {
GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
if (productCategory != null) {
String ebayCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
StoreCustomCategoryType categoryType = new StoreCustomCategoryType();
if (ebayCategoryId == null) {
categoryType.setName(productCategory.getString("categoryName"));
listAdd.add(categoryType);
} else {
categoryType.setCategoryID(new Long(ebayCategoryId));
categoryType.setName(productCategory.getString("categoryName"));
listEdit.add(categoryType);
}
}
}
if (listAdd.size() > 0) {
req = new SetStoreCategoriesRequestType();
categoryArrayType = new StoreCustomCategoryArrayType();
categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
req.setStoreCategories(categoryArrayType);
result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
}
if (listEdit.size() > 0) {
req = new SetStoreCategoriesRequestType();
categoryArrayType = new StoreCustomCategoryArrayType();
categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
req.setStoreCategories(categoryArrayType);
result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
}
//start at level 1 of categories
listAdd = FastList.newInstance();
listEdit = FastList.newInstance();
for (GenericValue catalogCategory : catalogCategories) {
GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
if (productCategory != null) {
String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
if (ebayParentCategoryId != null) {
List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategory.getString("productCategoryId")), UtilMisc.toList("sequenceNum ASC"));
for (GenericValue productCategoryRollup : productCategoryRollupList) {
productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryRollup.getString("productCategoryId")));
StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
if (ebayChildCategoryId == null) {
childCategoryType.setName(productCategory.getString("categoryName"));
listAdd.add(childCategoryType);
} else {
childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
childCategoryType.setName(productCategory.getString("categoryName"));
listEdit.add(childCategoryType);
}
}
}
if (listAdd.size() > 0) {
req = new SetStoreCategoriesRequestType();
categoryArrayType = new StoreCustomCategoryArrayType();
categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
req.setStoreCategories(categoryArrayType);
req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
}
if (listEdit.size() > 0) {
req = new SetStoreCategoriesRequestType();
categoryArrayType = new StoreCustomCategoryArrayType();
categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
req.setStoreCategories(categoryArrayType);
req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
}
}
}
//start at level 2 of categories
listAdd = FastList.newInstance();
listEdit = FastList.newInstance();
for (GenericValue catalogCategory : catalogCategories) {
GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
if (productCategory != null) {
List<GenericValue> productParentCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategory.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
for (GenericValue productParentCategoryRollup : productParentCategoryRollupList) {
String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productParentCategoryRollup.getString("productCategoryId"),context.get("partyId").toString());
if (ebayParentCategoryId != null) {
List<GenericValue> productChildCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productParentCategoryRollup.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
for (GenericValue productChildCategoryRollup : productChildCategoryRollupList) {
productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productChildCategoryRollup.getString("productCategoryId")));
StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
if (ebayChildCategoryId == null) {
childCategoryType.setName(productCategory.getString("categoryName"));
listAdd.add(childCategoryType);
} else {
childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
childCategoryType.setName(productCategory.getString("categoryName"));
listEdit.add(childCategoryType);
}
}
if (listAdd.size() > 0) {
req = new SetStoreCategoriesRequestType();