如何在android中使用magento api从购物车中删除商品?

时间:2015-06-22 13:01:21

标签: android magento ksoap2

我正在使用" shoppingCartProductRemove" api从magento中的购物车中删除商品。为此,我使用以下代码:

SoapObject item = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
                PropertyInfo pinfo = new PropertyInfo();
                String productid = productId.get(deleteProductPosition);
                pinfo.setName("product_id");
                pinfo.setValue(productid);
                pinfo.setType(String.class);
                item.addProperty(pinfo);

                pinfo = new PropertyInfo();
                String productsku = productSku.get(deleteProductPosition);
                pinfo.setName("sku");
                pinfo.setValue(productsku);
                pinfo.setType(String.class);
                item.addProperty(pinfo);

                pinfo = new PropertyInfo();
                int productQty = Qty.get(deleteProductPosition);
                pinfo.setName("qty");
                pinfo.setValue(productQty);
                pinfo.setType(Double.class);
                item.addProperty(pinfo);

SoapObject EntityArray = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
                EntityArray.addProperty("productsData", item);

            SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductRemove");
                request.addProperty("sessionId", sessionId);
                request.addProperty("quoteId", 118);
                request.addProperty("productsData", item);

                env.setOutputSoapObject(request);
                androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.call("", env);
                Object catrInfoObjs = env.getResponse();

但是我得到了xml pullparser异常。是否有任何参考从购物车中删除项目。需要帮助!!

1 个答案:

答案 0 :(得分:0)

I got it using the following code:

SoapObject item = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
                PropertyInfo pinfo = new PropertyInfo();

                pinfo.setName("product_id");
                pinfo.setValue(productId.get(deleteProductPosition));
                pinfo.setType(String.class);
                item.addProperty(pinfo);

                pinfo = new PropertyInfo();
                pinfo.setName("sku");
                pinfo.setValue(productSku.get(deleteProductPosition));
                pinfo.setType(String.class);
                item.addProperty(pinfo);
                int productQty = Qty.get(deleteProductPosition);
                pinfo = new PropertyInfo();
                pinfo.setName("qty");
                pinfo.setValue(productQty);
                pinfo.setType(Double.class);
                item.addProperty(pinfo);

                pinfo = new PropertyInfo();
                pinfo.setName("options");
                pinfo.setValue(" ");
                pinfo.setType(String[].class);
                item.addProperty(pinfo);


                SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
                EntityArray.addProperty("products",item);

                SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductRemove");
                request.addProperty("sessionId", sessionId);
                request.addProperty("quoteId", 74);
                request.addProperty("products",EntityArray);

                env.setOutputSoapObject(request);
                androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.call("", env);

                Object result = (Boolean) env.getResponse();