我正在magento中使用soap api构建android应用程序,它能够在移动设备上销售产品。我正在使用ksoap2库文件。
但问题是我无法使用功能shoppingCartProductAdd将产品添加到购物车。它给出错误产品的数据无效
因此,如果您有更好的方法将产品添加到购物车,请帮助我
这是我将产品添加到购物车的代码
SoapObject request;
Method_Name = "shoppingCartCreate";
SOAP_ACTION = "urn:Magento/shoppingCartCreate";
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
request = new SoapObject(NAMESPACE, Method_Name);
request.addProperty("sessionId", sessionId);
env.setOutputSoapObject(request);
androidHttpTransport.call("SOAP_ACTION", env);
cartId = env.getResponse().toString();
SoapObject loresponse = new SoapObject(NAMESPACE,
"shoppingCartProductEntity");
PropertyInfo pi = new PropertyInfo();
pi.setName("product_id");
pi.setValue(cartitem.getItemId());
pi.setType(String.class);
loresponse.addProperty(pi);
pi = new PropertyInfo();
pi.setName("sku");
pi.setValue(cartitem.getSku());
pi.setType(String.class);
loresponse.addProperty(pi);
pi = new PropertyInfo();
pi.setName("qty");
pi.setValue(cartitem.getQuantity());
pi.setType(Double.class);
loresponse.addProperty(pi);
request = new SoapObject(NAMESPACE, "shoppingCartProductAdd");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", cartId);
request.addProperty("productsData", loresponse);
env.setOutputSoapObject(request);
androidHttpTransport
.call("urn:Magento/shoppingCartProductAdd", env);
boolean result1po = (Boolean) env.getResponse();
}
catch (Exception ex) {
Log.e(TAG, "Error: " + ex.getMessage());
}