我正在使用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());
}
答案 0 :(得分:2)
使用以下代码创建ProductArray。我认为" shoppingCartProductEntityArray"缺少
//Create Product Array
SoapObject item = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pinfo = new PropertyInfo();
pinfo.setName("product_id");
pinfo.setValue("91");
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("sku");
pinfo.setValue("SFS-123");
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("qty");
pinfo.setValue("2");
pinfo.setType(Double.class);
item.addProperty(pinfo);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",item);
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductAdd");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", 166);
request.addProperty("products",EntityArray);