ResourcePath.CategoryCreate, newCategory));
if (id > -1) {
category.setId(id);
return id;
} else {
throw new ServiceException("Error inserting new Category");
}
} catch (NumberFormatException e) {
if (debug)
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AxisFault e) {
if (debug)
e.printStackTrace();
if(e.getMessage().indexOf("available_sort_by") > 0) {
System.out.println("Broken Magento API? Run this SQL code first\n" +
"update eav_attribute set is_required = 0 where attribute_code = 'available_sort_by';");
}
throw new ServiceException(e.getMessage());
}
} else {
// update existing category
List<Object> newCategory = new LinkedList<Object>();
newCategory.add(category.getId());
newCategory.add(category.getAllProperties());
if(!storeView.isEmpty()) {
newCategory.add(storeView);
}
try {
Boolean sucessed = (Boolean) soapClient.call(
ResourcePath.CategoryUpdate, newCategory);
if (!sucessed) {
throw new ServiceException("Error on update Category");
}
} catch (AxisFault e) {
if (debug)
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return category.getId();
}
}