Magento:将产品转移到客户的购物车android

时间:2014-08-22 05:26:21

标签: android magento ksoap2 android-ksoap2 ksoap

我正在使用android ksoap2和magento soap api V2制作购物车。我无法使用api shoppingCartProductMoveToCustomerQuote将购物车产品移至客户购物车。我收到错误消息'客户的报价不存在'。我使用了link

我使用下面的代码:

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

1 个答案:

答案 0 :(得分:0)

只有4个参数的

shoppingCartProductAdd 方法 的sessionId, quoteId, products \ productsData, storeId(可选)

,但是你发送的更多,所以删除

 request.addProperty("options",null);
 request.addProperty("bundle_option",null);
 request.addProperty("bundle_option_qty",null);
 request.addProperty("links",null);   

从您的代码中尝试。

如果需要,您可以将这些属性添加到 shoppingCartProductEntity 方法。 http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html了解更多详情