Android-Magento- How to add product to cart using ksop2 - android

I am building android application using soap api in magento which has ability to sell products on mobile.
I am using ksoap2 library file.
But problem is that i am not able to add product to cart using function shoppingCartProductAdd.
Its gives error Product’s data is not valid
So please help me if you have better methode to add a product to cart
Here is my code that add product to 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 to Create ProductArray.I think "shoppingCartProductEntityArray" is 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);

Related

Magento: transfer product to customer's cart android

I am making shopping cart using android ksoap2 and magento soap api V2. I am unable to move the cart products to customer's cart using the api shoppingCartProductMoveToCustomerQuote. I am getting error as 'Customer’s quote is not existed'.I used the link
I have use the code below:
private String response,id;
String[][] Products = new String[][] {{"20","20","1"}};
protected String doInBackground(String... params)
{
try
{
//SoapEnvelop.VER11 is SOAP Version 1.1 constant
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.xsd = SoapSerializationEnvelope.XSD;
envelope.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE,"login");
request.addProperty("username", "***");
request.addProperty("apiKey", "*********");
//envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL);
try
{
transport.debug=true;
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + "shoppingCartProductAdd", envelope);
// transport.call(NAMESPACE + SOAP_ACTION_PREFIX + "catalogProductList", envelope);
response=(String) envelope.getResponse();
String sessionId = response.toString();
Log.d("The session Id is:",sessionId);
SoapObject SingleProduct = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pi = new PropertyInfo();
pi.setName("product_id");
pi.setValue(Integer.parseInt(Products[0][0]));
pi.setType(Integer.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("sku");
pi.setValue(Products[0][1]);
pi.setType(String.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("qty");
pi.setValue(Products[0][2]);
pi.setType(Double.class);
SingleProduct.addProperty(pi);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",SingleProduct);
request = new SoapObject(NAMESPACE,METHOD_NAME);
//adding the propery such as sessionId and Customerdata for request
request.addProperty("sessionId",sessionId );
request.addProperty("quoteId",100);
request.addProperty("products",EntityArray);
request.addProperty("options",null);
request.addProperty("bundle_option",null);
request.addProperty("bundle_option_qty",null);
request.addProperty("links",null);
//request.addProperty("store_id", 1);
envelope.setOutputSoapObject(request);
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD_NAME, envelope);
//getting the response which is the customerId
Log.d("Test", "request: " + transport.requestDump);
Log.d("Test", "response: " + transport.responseDump);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
shoppingCartProductAdd method having only 4 parameters
sessionId,
quoteId,
products\productsData ,
storeId (optional)
, but your sending more then that, so remove
request.addProperty("options",null);
request.addProperty("bundle_option",null);
request.addProperty("bundle_option_qty",null);
request.addProperty("links",null);
from your code and try.
You can add these properties to the shoppingCartProductEntity methods if you want.
http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html for more details

ParseException: Unparseable date With Ksoap Parsing

I am developing an app in which i nee dto parse "date" in KSOAP base webservices,i need to Pass Date at server with formate of "MM/dd/yyyy" so i have use SimepldateFormate and pass Date string to that date class but here something is wrong that getting me error like
Error:
08-13 14:45:20.031: ERROR/KsoapDemoActivity(562): Exception=>java.text.ParseException: Unparseable date: "08/01/2011"
i have also rend request with Date Class in KSoap like pi1.setType(Date.class); but not getting solve.I have also tried with make Class MarshalDate mdouble = new MarshalDate(); but not getting solution
can you please help me out this
Here is my code
private void InsertClientDetailForMobApp() {
// TODO Auto-generated method stub
try {
String NAMESPACE = "urn:MobileApplicationIntf-IMobileApplication";// "http://tempuri.org/";
String METHOD_NAME = "InsertClientDetailForMobApp";
String SOAP_ACTION = "urn:MobileApplicationIntf-IMobileApplication#InsertClientDetailForMobApp";
String URL = ("URL");//
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("asfirstname");
pi1.setValue("Nikunj");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi2 = new PropertyInfo();
pi1.setName("asLastName");
pi1.setValue("patel");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi3 = new PropertyInfo();
pi1.setName("asNationalID");
pi1.setValue("25125514");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi4 = new PropertyInfo();
pi1.setName("asCountryissued");
pi1.setValue("asdasdasd");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi5 = new PropertyInfo();
pi1.setName("asLicenceNo");
pi1.setValue("asdasd");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi6 = new PropertyInfo();
pi1.setName("asPassportNo");
pi1.setValue("12512513221321");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi7 = new PropertyInfo();
pi1.setName("asGender");
pi1.setValue("M");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi8 = new PropertyInfo();
pi1.setName("asAddress1");
pi1.setValue("Indasdas asd as aia");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi9 = new PropertyInfo();
pi1.setName("asAddress2");
pi1.setValue("asdas asd asdasdas ");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi10 = new PropertyInfo();
pi1.setName("asCountry");
pi1.setValue("India");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi11 = new PropertyInfo();
pi1.setName("asCity");
pi1.setValue("Ahmedabad");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi12 = new PropertyInfo();
pi1.setName("asProvince");
pi1.setValue("Gujarat");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi13 = new PropertyInfo();
pi1.setName("asZip");
pi1.setValue("356256");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi14 = new PropertyInfo();
pi1.setName("asDayTelephone");
pi1.setValue("15165165565456");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi15 = new PropertyInfo();
pi1.setName("asEveTelephone");
pi1.setValue("5545654654");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi16 = new PropertyInfo();
pi1.setName("asFAX");
pi1.setValue("54145615");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi17 = new PropertyInfo();
pi1.setName("asEmail");
pi1.setValue("nkpatel#asd-infotech.com");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi18 = new PropertyInfo();
pi1.setName("asUserName");
pi1.setValue("Nik123");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi19 = new PropertyInfo();
pi1.setName("asPassword");
pi1.setValue("India");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi20 = new PropertyInfo();
pi1.setName("asLanguege");
pi1.setValue("English");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi21 = new PropertyInfo();
pi1.setName("asQuestion1");
pi1.setValue("Question1");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi22 = new PropertyInfo();
pi1.setName("asAnswer1");
pi1.setValue("Nothing1");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi23 = new PropertyInfo();
pi1.setName("asQuestion2");
pi1.setValue("what1");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi24 = new PropertyInfo();
pi1.setName("asSSN");
pi1.setValue("123456");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi25 = new PropertyInfo();
pi1.setName("asAnswer2");
pi1.setValue("Nothing2");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi26 = new PropertyInfo();
pi1.setName("asPrimaryCurrency");
pi1.setValue("INR");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi27 = new PropertyInfo();
pi1.setName("asSecondaryCurrency");
pi1.setValue("USD");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi28 = new PropertyInfo();
pi1.setName("asAgentID");
pi1.setValue("456");
pi1.setType(String.class);
Request.addProperty(pi1);
PropertyInfo pi29 = new PropertyInfo();
pi1.setName("asBranchCode");
pi1.setValue("Tcom India");
pi1.setType(String.class);
Request.addProperty(pi1);
String str_date = "08/01/2011";
// yyyy-MM-dd'T'HH:mm:ss
DateFormat formatter;
Date date;
//formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
formatter = new SimpleDateFormat("MM-dd-yyyy");
date = (Date) formatter.parse(str_date);
PropertyInfo pi30 = new PropertyInfo();
pi1.setName("dtDOB");
pi1.setValue(date);
pi1.setType(Date.class);
Request.addProperty(pi1);
/*
* Call the web service and retrieve result ... how luvly <3
*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
URL);
MarshalDate mdouble = new MarshalDate();
mdouble.register(envelope);
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.i("TAG", "soapResponse=>" + envelope.getResponse());
} catch (Exception e) {
soapResponseObject = null;
Log.e(TAG, "niraliwebservice() Exception=>" + e);
}
}
MarshalDate
package com.KsoapDemo;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.kobjects.isodate.IsoDate;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
public class MarshalDate implements Marshal
{
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME);
}
public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, "DateTime", Date.class, this);
}
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(IsoDate.dateToString((Date) obj, IsoDate.DATE_TIME));
}
}
UPDATE:
I have Change "08-01-2012" to "08/01/2012"
but now it raise me error
SoapFault - faultcode: 'SOAP-ENV:Server' faultstring: 'Access violation at address 00405818 in module 'MobileApp.exe'. Read of address 69570A03' faultactor: '' detail: null
Use / instead of - in simpleDateFormat...
formatter = new SimpleDateFormat("MM/dd/yyyy");
you've used the wrong pattern in your SimpleDateFormat class
use:
formatter = new SimpleDateFormat("MM/dd/yyyy");
instead of:
formatter = new SimpleDateFormat("MM-dd-yyyy");
Register your MarshalDate to your SOAP Envelope:
MarshalDate _MarshalDate = new MarshalDate();
_MarshalDate.register(soapEnvelope);
Then continue with your properties until the date that you want to pass and do this:
PropertyInfo _PropertyInfo = new PropertyInfo();
_PropertyInfo.setName("yourParameterInYourMethodeInTheWebService");
_PropertyInfo.setType(Date.class);
_PropertyInfo.setValue(yourVariableOfTypeDate);
soapReq.addProperty(_PropertyInfo);

Android KSOAP2 Error

I am using the jar(ksoap2-android-assembly-2.6.5-jar-with-dependencies) and have a web -
services.url = http://62.244.199.18:8888/ergo-ergoService-context-root/ergoSoapHttpPort?WSDL
and my code is below
private static final String METHOD_NAME = "checkloginnew";
private static final String SOAP_ACTION = "http://ergoconn/Ergo.wsdl/checkloginnew";
private static final String NAMESPACE = "http://ergoconn/Ergo.wsdl";
private static final String URL = "http://62.244.199.18:8888/ergo-ergoService-context-root/ergoSoapHttpPort?WSDL";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("pPid");
pi.setValue(1149688);
pi.setType(BigDecimal.class);
request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("pPass");
pi2.setValue("074920");
pi2.setType(String.class);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
But I get an error "Caught exception while handling request: unrecognized operation: {http://ergoconn/Ergo.wsdl}checkloginnew"
In my httpTransport.responseDump:
<faultcode>env:Client</faultcode><faultstring>Caught exception while handling request: unrecognized operation: {http://ergoconn/Ergo.wsdl}checkloginnew</faultstring></env:Fault>
Thanks very much

Web Service return null in Android

I have a web service that I use in my android project. One method in my web service return null in android with ksoap2. When I debug the project, envelope is returning like this:
GPSYerBilgisiGetirResponse{GPSYerBilgisiGetirResult=anyType{}; }
Out of android, I run the web service and give parameter to method, returning data like this:
<ArrayOfFirma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Firma>
<gpsilce>BEYOĞLU</gpsilce>
<gpssemt>KASIMPAŞA</gpssemt>
</Firma>
</ArrayOfFirma>
This is my function for using connect to web service
private String[] konumGetir(String ParamPK){
PropertyInfo pk = new PropertyInfo();
pk.name= "pk";
pk.setValue(ParamPK);
pk.type = PropertyInfo.STRING_CLASS;
SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
request.addProperty(pk);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut=request;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call("http://tempuri.org/GPSYerBilgisiGetir", envelope);
SoapObject response = (SoapObject) envelope.getResponse();
konumList=new String[1];
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject firmalar = (SoapObject) property;
konumList[0]=firmalar.getProperty("gpssemt") + "-" + firmalar.getProperty("gpsilce");
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return konumList;
}
This is my web service method:
<WebMethod()> _
Public Function GPSYerBilgisiGetir(ByVal pk As String) As List(Of Firma)
Dim konumlist As New List(Of Firma)
Dim dg As New dgetir("SELECT DISTINCT ILCE,SEMT FROM GPSYERBILGISI WHERE PK='" + pk + "'")
While dg.dtr.Read
Dim gpskonum As New Firma
gpskonum.gpsilce = dg.dtr.Item("ILCE")
gpskonum.gpssemt = dg.dtr.Item("SEMT")
konumlist.Add(gpskonum)
End While
dg.close()
Return konumlist
End Function
Try this code.
private String[] konumGetir(String ParamPK){
SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
request.addProperty("pk", ParamPK);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_NAME, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
int childCount = result.getPropertyCount();
konumList = new String[childCount];
SoapObject tempArray[] = new SoapObject[childCount];
int i;
for (i = 0; i < childCount; i++) {
tempArray[i] = (SoapObject) result.getProperty(i);
konumList[i] = tempArray.getProperty(0).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return konumList;
}
Hope it helps.

Android : how to pass a integer value to service using KSOAP in android

Not able to pass an integer value to the service request.The value that reaches service request becomes null
Here is my code
private static final String METHOD_NAME ="GetPrivileges";
private static final String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
private static final String URL ="http://192.168.5.219/NTLS_Authorization
/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
public void call() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi=new PropertyInfo();
pi.type=PropertyInfo.INTEGER_CLASS;
pi.setName("RoleID");
pi.setValue(3);
pi.setNamespace(NAMESPACE);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
public void call(int number)
{
try
{
String METHOD_NAME ="GetPrivileges";
String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
String URL ="http://192.168.5.219/NTLS_Authorization/AuthorisationManager.asmx";
final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("RoleID",number);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
String resultData = result.toString();
Log.v("Result==>",resultData);
}
catch(Exception e)
{
e.printStackTrace();
}
}
simply you can add this
requestObject.addProperty("RoleID",3);
May be try this code //note don't put directly number(3 in ur case) instead pass it as parameter ...
final SoapObject requestObject = new SoapObject(Constants.NAMESPACE,METHOD_NAME );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
requestObject.addProperty("RoleID",number);
envelope.setOutputSoapObject(requestObject);
AndroidHttpTransport androidHttpTransport =new AndroidHttpTransport(Constants.URL);
try
{
androidHttpTransport.call(Constants.SOAP_ACTION+METHOD_NAME, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.v("result",response.toString());
}
catch(Exception e)
{
e.printStackTrace();
}

Categories

Resources