3

我正在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());

    }
4

1 回答 1

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);
于 2014-12-02T06:19:05.480 回答