3

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

    }
Karthik
  • 53
  • 5

1 Answers1

2

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);
Harshal Bhatt
  • 731
  • 10
  • 25
  • i tried this solution, but i'm getting SoapFault - faultcode: '1022' faultstring: 'Please specify the product required option(s).' How to add the associativeArray to the product array? – Rahul Nov 30 '15 at 08:06