如何在一个soap对象中添加两个数组用于magento中的账单和送货地址?

问题描述 投票:0回答:1

我正在使用 magento Soap api 添加送货和帐单地址

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

但它没有添加并给出异常客户地址数据为空

请帮帮我......花了一天时间,但我仍然找不到任何东西

web-services magento magento-soap-api
1个回答
3
投票

在我看来,您想在通过 SOAP 创建订单期间添加客户帐单/送货地址。

您需要使用数组传递地址数据。有关详细信息,请单击此处并查看 magento 的官方 SOAP 文档。

$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);
© www.soinside.com 2019 - 2024. All rights reserved.