Android-Magento- How to add product to cart using ksop2 -
i building android application using soap api in magento has ability sell products on mobile. using ksoap2 library file.
but problem not able add product cart using function shoppingcartproductadd. gives error product’s data not valid
so please me if have better methode add product cart
here code add product cart
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()); }
use below code create productarray.i think "shoppingcartproductentityarray" missing
//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);
Comments
Post a Comment