在 android 中使用 magento soap api 创建客户地址
creating address of a customer using magento soap api in android
在我的应用程序中,使用 customerCustomerCreate API 创建客户并获取客户 ID。现在我的要求是创建客户的地址,为此我调用 customerAddressCreate api。但不知何故我无法创建客户地址。我
尝试使用以下代码:
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, "login");
request.addProperty("username", "user");
request.addProperty("apiKey", "apikey");
env.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
Object result = env.getResponse();
Log.e("sessionId", result.toString());
String sessionId = result.toString();
request = new SoapObject(NAMESPACE, "customerAddressCreate");
request.addProperty("sessionId", sessionId);
request.addProperty("customerId",custId);
SoapObject customerEntity = new SoapObject(NAMESPACE, "customerAddressEntityCreate");
customerEntity.addProperty("city", "bangalore");
customerEntity.addProperty("company", "outthinking");
customerEntity.addProperty("country_id", "01");
customerEntity.addProperty("fax", "08012345");
customerEntity.addProperty("firstname", "amit");
customerEntity.addProperty("lastname", "chandra");
customerEntity.addProperty("middlename", "raj");
customerEntity.addProperty("postcode", "560007");
customerEntity.addProperty("prefix", "a");
customerEntity.addProperty("region_id", 03);
customerEntity.addProperty("region", "karnataka");
customerEntity.addProperty("street",Arrays.toString(myStrings));
customerEntity.addProperty("suffix", "ac");
customerEntity.addProperty("telephone", "+91-9962025341");
customerEntity.addProperty("is_default_billing", false);
customerEntity.addProperty("is_default_shipping", false);
request.addProperty("addressdata", customerEntity);
} catch (Exception e) {
e.printStackTrace();
}
其中 myStrings 是街道字符串数组。但我收到以下错误:
SoapFault - faultcode: '100' faultstring: 'Please enter the first name.
Please enter the last name.
Please enter the street.
Please enter the city.
Please enter the telephone number.
Please enter the zip/postal code.
Please enter the country.' faultactor: 'null' detail: null
我的代码有什么问题?为此提供解决方案?
我得到了解决方案。如果任何机构仍然面临问题,请尝试使用此代码。它对我有用。
request = new SoapObject(NAMESPACE, "customerAddressCreate");
request.addProperty("sessionId", sessionId);
//int customerId = Integer.parseInt(custId);
request.addProperty("customerId","custId");
SoapObject customerEntity = new SoapObject(NAMESPACE, "customerAddressEntityCreate");
customerEntity.addProperty("city", "city");
customerEntity.addProperty("company","");
customerEntity.addProperty("country_id", "IN");
customerEntity.addProperty("fax", "");
customerEntity.addProperty("firstname", fname);
customerEntity.addProperty("lastname", lName);
customerEntity.addProperty("middlename", "");
customerEntity.addProperty("postcode", zipCode);
customerEntity.addProperty("prefix", "");
customerEntity.addProperty("region_id",1);
customerEntity.addProperty("region", region);
SoapObject streetEntity = new SoapObject(NAMESPACE, "street");
streetEntity.addProperty("street", street1);
//streetEntity.addProperty("street", street2);
customerEntity.addProperty("street",streetEntity);
customerEntity.addProperty("suffix", "");
customerEntity.addProperty("telephone", "8147555522");
customerEntity.addProperty("is_default_billing", true);
customerEntity.addProperty("is_default_shipping", false);
request.addProperty("addressData", customerEntity);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
result = env.getResponse();
您只需将名称 "addressdata" 更改为 addressData。
在我的应用程序中,使用 customerCustomerCreate API 创建客户并获取客户 ID。现在我的要求是创建客户的地址,为此我调用 customerAddressCreate api。但不知何故我无法创建客户地址。我
尝试使用以下代码:
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, "login");
request.addProperty("username", "user");
request.addProperty("apiKey", "apikey");
env.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
Object result = env.getResponse();
Log.e("sessionId", result.toString());
String sessionId = result.toString();
request = new SoapObject(NAMESPACE, "customerAddressCreate");
request.addProperty("sessionId", sessionId);
request.addProperty("customerId",custId);
SoapObject customerEntity = new SoapObject(NAMESPACE, "customerAddressEntityCreate");
customerEntity.addProperty("city", "bangalore");
customerEntity.addProperty("company", "outthinking");
customerEntity.addProperty("country_id", "01");
customerEntity.addProperty("fax", "08012345");
customerEntity.addProperty("firstname", "amit");
customerEntity.addProperty("lastname", "chandra");
customerEntity.addProperty("middlename", "raj");
customerEntity.addProperty("postcode", "560007");
customerEntity.addProperty("prefix", "a");
customerEntity.addProperty("region_id", 03);
customerEntity.addProperty("region", "karnataka");
customerEntity.addProperty("street",Arrays.toString(myStrings));
customerEntity.addProperty("suffix", "ac");
customerEntity.addProperty("telephone", "+91-9962025341");
customerEntity.addProperty("is_default_billing", false);
customerEntity.addProperty("is_default_shipping", false);
request.addProperty("addressdata", customerEntity);
} catch (Exception e) {
e.printStackTrace();
}
其中 myStrings 是街道字符串数组。但我收到以下错误:
SoapFault - faultcode: '100' faultstring: 'Please enter the first name.
Please enter the last name.
Please enter the street.
Please enter the city.
Please enter the telephone number.
Please enter the zip/postal code.
Please enter the country.' faultactor: 'null' detail: null
我的代码有什么问题?为此提供解决方案?
我得到了解决方案。如果任何机构仍然面临问题,请尝试使用此代码。它对我有用。
request = new SoapObject(NAMESPACE, "customerAddressCreate");
request.addProperty("sessionId", sessionId);
//int customerId = Integer.parseInt(custId);
request.addProperty("customerId","custId");
SoapObject customerEntity = new SoapObject(NAMESPACE, "customerAddressEntityCreate");
customerEntity.addProperty("city", "city");
customerEntity.addProperty("company","");
customerEntity.addProperty("country_id", "IN");
customerEntity.addProperty("fax", "");
customerEntity.addProperty("firstname", fname);
customerEntity.addProperty("lastname", lName);
customerEntity.addProperty("middlename", "");
customerEntity.addProperty("postcode", zipCode);
customerEntity.addProperty("prefix", "");
customerEntity.addProperty("region_id",1);
customerEntity.addProperty("region", region);
SoapObject streetEntity = new SoapObject(NAMESPACE, "street");
streetEntity.addProperty("street", street1);
//streetEntity.addProperty("street", street2);
customerEntity.addProperty("street",streetEntity);
customerEntity.addProperty("suffix", "");
customerEntity.addProperty("telephone", "8147555522");
customerEntity.addProperty("is_default_billing", true);
customerEntity.addProperty("is_default_shipping", false);
request.addProperty("addressData", customerEntity);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
result = env.getResponse();
您只需将名称 "addressdata" 更改为 addressData。