How to Add two arrays in one soap object for billing and shipping address in magento?
Asked Answered
K

1

11

I am using magento soap api to add shipping and billing address as

" SoapObject item1 = new SoapObject(NAMESPACE, "shoppingCartCustomerAddressEntity");

          PropertyInfo pinfo = new PropertyInfo();
          pinfo.setName("mode");
          pinfo.setValue("shipping");
          pinfo.setType(String.class);
         item1.addProperty(pinfo);

          pinfo = new PropertyInfo();
          pinfo.setName("firstname");
          pinfo.setValue(firstname1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("lastname");
          pinfo.setValue(lastname1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);


          pinfo = new PropertyInfo();
          pinfo.setName("company");
          pinfo.setValue(company1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("street");
          pinfo.setValue(street1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("city");
          pinfo.setValue(city1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("region");
          pinfo.setValue(region1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("postcode");
          pinfo.setValue(postcode1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("country_id");
          pinfo.setValue(country1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("telephone");
          pinfo.setValue(telephone1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("fax");
          pinfo.setValue(fax1);
          pinfo.setType(String.class);
          item1.addProperty(pinfo);



          pinfo = new PropertyInfo();
          pinfo.setName("is_default_shipping");
          pinfo.setValue(1);
          pinfo.setType(Integer.class);
          item1.addProperty(pinfo);







          SoapObject entityArray = new SoapObject(NAMESPACE, "shoppingCartCustomerAddressEntityArray");
          entityArray.addProperty("customer",item1);

SoapObject item2 = new SoapObject(NAMESPACE, "shoppingC");

          PropertyInfo pinfo1 = new PropertyInfo();
          pinfo1.setName("mode");
          pinfo1.setValue("billing");
          pinfo1.setType(String.class);
         item2.addProperty(pinfo1);

          pinfo1 = new PropertyInfo();
          pinfo1.setName("firstname");
          pinfo1.setValue(firstname1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("lastname");
          pinfo1.setValue(lastname1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);


          pinfo1 = new PropertyInfo();
          pinfo1.setName("company");
          pinfo1.setValue(company1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("street");
          pinfo1.setValue(street1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("city");
          pinfo1.setValue(city1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("region");
          pinfo1.setValue(region1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("postcode");
          pinfo1.setValue(postcode1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("country_id");
          pinfo1.setValue(country1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("telephone");
          pinfo1.setValue(telephone1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("fax");
          pinfo1.setValue(fax1);
          pinfo1.setType(String.class);
          item2.addProperty(pinfo1);



          pinfo1 = new PropertyInfo();
          pinfo1.setName("is_default_billing");
          pinfo1.setValue(0);
          pinfo1.setType(Integer.class);
          item2.addProperty(pinfo1);

          SoapObject entityArray2 = new SoapObject(NAMESPACE, "shoppingCartCustomerAddressEntityArray");
          entityArray2.addProperty("customer",item2);


          Log.e("itemsad2222", entityArray2.toString());

          SoapObject entityArray3 = new SoapObject(NAMESPACE, "shoppingCartCustomerAddressEntityArray");
          entityArray3.addProperty("customer",entityArray);
          entityArray3.addProperty("customer",entityArray2);

      SoapObject request = new SoapObject(NAMESPACE, "shoppingCartCustomerAddresses");
      request.addProperty("sessionId", SessionId);
      request.addProperty("quoteId", CartId);
      request.addProperty("customer",entityArray3);"

but its not adding and giving exception customer address data is empty

Help me out please...it took a day but i still could not find anythng

Klein answered 24/8, 2015 at 12:8 Comment(0)
C
3

It seems to me you want to add customer billing/shipping address during order creation via SOAP.

You need to pass addresses data using array. for details click here and take a look at magento's official SOAP doc.

$user = 'apiUser';
$password = 'apiKey';
    $proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
    $sessionId = $proxy->login($user, $password);
    $cartId = $proxy->shoppingCartCreate($sessionId, 1);
    // load the customer list and select the first customer from the list
    $customerList = $proxy->customerCustomerList($sessionId, array());
    $customer = (array) $customerList[0];
    $customer['mode'] = 'customer';
    $proxy->shoppingCartCustomerSet($sessionId, $cartId, $customer);
    // load the product list and select the first product from the list
    $productList = $proxy->catalogProductList($sessionId);
    $product = (array) $productList[0];
    $product['qty'] = 1;
    $proxy->shoppingCartProductAdd($sessionId, $cartId, array($product));

    $address = array(
        array(
            'mode' => 'shipping',
            'firstname' => $customer['firstname'],
            'lastname' => $customer['lastname'],
            'street' => 'street address',
            'city' => 'city',
            'region' => 'region',
            'telephone' => 'phone number',
            'postcode' => 'postcode',
            'country_id' => 'country ID',
            'is_default_shipping' => 0,
            'is_default_billing' => 0
        ),
        array(
            'mode' => 'billing',
            'firstname' => $customer['firstname'],
            'lastname' => $customer['lastname'],
            'street' => 'street address',
            'city' => 'city',
            'region' => 'region',
            'telephone' => 'phone number',
            'postcode' => 'postcode',
            'country_id' => 'country ID',
            'is_default_shipping' => 0,
            'is_default_billing' => 0
        ),
    );
     // add customer address
    $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address);
    // add shipping method
    $proxy->shoppingCartShippingMethod($sessionId, $cartId, 'flatrate_flatrate');

    $paymentMethod =  array(
        'po_number' => null,
        'method' => 'checkmo',
        'cc_cid' => null,
        'cc_owner' => null,
        'cc_number' => null,
        'cc_type' => null,
        'cc_exp_year' => null,
        'cc_exp_month' => null
    );
     // add payment method
    $proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod);
     // place the order
    $orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null);
Carmarthenshire answered 25/8, 2015 at 5:55 Comment(6)
I am able to provide adress and then after its giving exception shipping method is not available..? i searched alot didnt find any specific answer can you plz help me out in this?Klein
need to enable Flat Rate shipping method. because this script is using Flat Rate shipping method look this line $proxy->shoppingCartShippingMethod($sessionId, $cartId, 'flatrate_flatrate'); here flatrate_flatrate means to Flat Rate shipping method.Carmarthenshire
yes sir i have enabled flatrate, i am also getting shipping method list as flat rate but when i set shipping method as flatrate_flatrate in my java code it throws me the exception that shipping method is not availableKlein
request = new SoapObject(NAMESPACE, "shoppingCartShippingMethod"); request.addProperty("sessionId", SessionId); request.addProperty("quoteId", CartId); request.addProperty("shippingMethod", "freeshipping_freeshipping"); Log.e("shippingrespomnse...", request.toString()); env.setOutputSoapObject(request); androidHttpTransport.call("", env); SoapObject methodset; methodset = (SoapObject) env.getResponse();Klein
Hi @Klein did you found any solution to this, am also getting same issue (customer address data is empty ) please let me know the solution .Thanks :)Dyane
@syed hey man i searched but couldnt get anythng did you got some stuffs to move ?Klein

© 2022 - 2024 — McMap. All rights reserved.