Magento: transfer product to customer's cart android - 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

Related

getting error while calling soap request in android?

I am using Ksoap2 android assembly 2.4 in my android application.I am try to call the web service by using soap.But I am getting the error at transport.call(soapAction, envelop); this line.
LOGCaT:
org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}soap:Fault>#1:301 in java.io.InputStreamReader#41743310)
And Here my code is:
String url = "http://192.168.56.1:8080/CxfWebservice/webservices/Calculator";
// String namespace = "http://localhost:8080/wsdl";
String namespace = "http://192.160.59.1:8080/wsdl";
String methodname = "sum";
public static void SoapOperation(String url, String method_name,
String name_space) throws Exception {
String soapAction = name_space + method_name;
SoapObject request = new SoapObject(name_space, method_name);
PropertyInfo p = new PropertyInfo();
p.setName("arg0");
p.setValue(5);
p.setType(Integer.TYPE);
PropertyInfo p1 = new PropertyInfo();
p1.setName("arg1");
p1.setValue(15);
p1.setType(Integer.TYPE);
request.addProperty(p );
request.addProperty(p1);
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelop.setOutputSoapObject(request);
envelop.dotNet = true;
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
transport.call(soapAction, envelop);
String xml = transport.responseDump;
System.out.println("the response xml is:"+xml);
}
above is my code with please give me a solution for this.
Here is an example. Use this code
public void InteractWithWebService() {
try {
final String URL = con.getResources().getString(R.string.URL);
final String NameSpace = con.getResources().getString(
R.string.NAMESPACE);
final String MethodName = "sum";
final String SOAP_ACTION = con.getResources().getString(
R.string.SOAP_ACTION)
+ MethodName;
SoapObject Request = new SoapObject(NameSpace, MethodName);
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
Request.addProperty("param_name", Object_name.getText().toString()
.trim());
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htp = new HttpTransportSE(URL);
htp.call(SOAP_ACTION, soapEnvelop);
// SoapObject response;
SoapPrimitive resultString = (SoapPrimitive) soapEnvelop
.getResponse();
if (resultString != null) {
status = Integer.parseInt(resultString.toString());
}
} catch (Exception ex) {
status = -1;
}
}
Add these lines in your strings file
<string name="NAMESPACE">http://tempuri.org/</string>
<string name="URL">http://Your_Localhost_address/Name_of_Service.svc</string>
<string name="SOAP_ACTION">http://tempuri.org/IName_of_Service/</string>

android soap web service - not retrieving output

private final String zipCodenameSpace ="http://www.webserviceX.NET/";
private final String zipURL="http://www.webserviceX.net/uszip.asmx";
private final String zipSoapAction ="http://www.webserviceX.NET/GetInfoByCity";
private final String zipMethodName="GetInfoByCity";
SoapObject request = new SoapObject(zipCodenameSpace, zipMethodName);
PropertyInfo cityInfo = new PropertyInfo();
cityInfo.setName("USCity");
cityInfo.setValue(city);
// cityInfo.setType(String.class);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
request.addProperty(cityInfo);
TextView tv = (TextView) findViewById(R.id.tv1);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(zipURL);
try {
androidHttpTransport.call(zipSoapAction, envelope);
// Object response =(SoapObject) envelope.getResponse();
SoapObject response = (SoapObject) envelope.getResponse();
Log.d("This is an element", response.toString());
// tv.setText(response.toString());
// return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
Showing null exception. Error is occurring at soapObject response.
I tried to use soap primitive but not working. Please help me where the problem is
Given Webservice returns xml.
cityInfo.setValue(city);
Where are you fetching this "city" value in your code? I think thats the problem. For testing you can set it as string directly here.like "NewYork".

error that occurs while the data from the webservice Ksoap

error occurs when requesting data from the internet in ksoap object
public String[] getProfile(String email) {
String[] profileArray = new String[3];
METHOD_NAME = "getProfile";
SoapObject getprofileSoapObject = new SoapObject(NAMESPACE,METHOD_NAME);
//To avoid code duplication getproperty. Set info
getprofileSoapObject.addProperty(setProperty("email", email));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getprofileSoapObject);
HttpTransportSE http = new HttpTransportSE(URL);
try { //call httptransport
http.call(SOAP_ACTION, envelope);
SoapObject SoapObject2 = (SoapObject) envelope.bodyIn;
//Set profile detail
profileArray[0] = SoapObject2.getProperty(0).toString();
profileArray[1] = SoapObject2.getProperty(1).toString();
profileArray[2] = SoapObject2.getProperty(2).toString();
return profileArray;
} catch (Exception e) {
//System.out.println(e.getMessage());
}
return profileArray;
}
NullPointerException error occurs after http.call

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

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

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.

Categories

Resources