gpt4 book ai didi

Android-Magento- 如何使用 ksop2 将产品添加到购物车

转载 作者:太空狗 更新时间:2023-10-29 13:30:27 27 4
gpt4 key购买 nike

我正在使用 magento 中的 soap api 构建 android 应用程序,它能够在移动设备上销售产品。我正在使用 ksoap2 库文件。

但问题是我无法使用函数 shoppingCartProductAdd 将产品添加到购物车。它给出错误 Product's data is not valid

如果您有更好的方法将产品添加到购物车,请帮助我

这是我将产品添加到购物车的代码

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());

}

最佳答案

使用下面的代码创建 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);

关于Android-Magento- 如何使用 ksop2 将产品添加到购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16075749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com