3

Hope someone can help me with this. I am building nusoap client using the following partial WSDL:

      <s:element name="SavePrestaPicklist">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="USERNAME" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PASSWORD" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="BRANCH" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="CUSTOMERNUMBER" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="CUSTOMERPO" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="SHIPMETHOD" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PRESTAPO" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PICKITEMS" type="tns:ArrayOfPICKITEM" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfPICKITEM">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="PICKITEM" nillable="true" type="tns:PICKITEM" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="PICKITEM">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="PARTNUMBER" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="BRANCH" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="MFRCODE" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="QUANTITY" type="s:string" />
        </s:sequence>
      </s:complexType>

My client looks like this:

   $orderdata = getorder('123');
   $orderdata = array(
        'USERNAME' => $config['export_username'],
        'PASSWORD' => $config['export_password'],
        'BRANCH' => '01',
        'CUSTOMERNUMBER' => $data['order']['address1'],
        'CUSTOMERPO' => $data['order']['gift_message'],
        'SHIPMETHOD' => $shipMethod,
        'PRESTAPO' => $data['order']['id_order']);

        // Build the pickitems array of pickitem.

        $pickitems = array();
        foreach($data['products'] as $item) {

            $pickitem = array(
                'PARTNUMBER' => $item['name'],
                'BRANCH' => '01',
                'MFRCODE' => '642',
                'QUANTITY' => $item['product_quantity']);

            $pickitems[] = $pickitem;
        }
        $data['PICKITEMS'] = $pickitems;

    $usingWsdl = true;
    $client = new nusoap_client($config['export_wsdl'], $usingWsdl);

    $response = $client->call('SavePrestaPicklist', $orderdata);

This isn't working and sends a PICKITEMS like this:

<PICKITEMS>
    <0>
       <PARTNUMBER>BLAH</PARTNUMBER>
       <BRANCH>BLAH</BRANCH>
         ETC.
    </0>
    <1>
        ANOTHER ITEM SET
    </1>
 </PICKITEMS>  

What I want is this:

<PICKITEMS>
    <PICKITEM>
       <PARTNUMBER>BLAH</PARTNUMBER>
       <BRANCH>BLAH</BRANCH>
         ETC.
    </PICKITEM>
    <PICKITEM>
        ANOTHER ITEM SET
    </PICKITEM>
 </PICKITEMS>

Since you can't have duplicate 'PICKITEM' keys in PHP I can't figure out how to do this. Any help would be appreciated.

  • What is the structure of your server function SavePrestaPicklist? the order of the parameters and type. You could serialize the variable $orderdata in the client side and then unserialize it in server side before calling SavePrestaPicklist. – satrun77 Jul 20 '11 at 01:47

2 Answers2

0
'PICKITEMS' => 
    array (
        'PICKITEM' => 
            array(
                0 => array('PARTNUMBER' => 'param1', 'BRANCH' => 'value1'),
                1 => array('PARTNUMBER' => 'param2', 'BRANCH' => 'value2')
        )
    )
AXE
  • 16
  • 2
0

You can send raw XML with the $client->send() method. Here is a full working example:

require_once('nusoap/lib/nusoap.php');

$endpoint = "http://yoursoapserver.com/SomeSoapService";

$client = new nusoap_client($endpoint, false);

$msg = $client->serializeEnvelope("
<ns1:insertuser xmlns:1="http://yoursoapserver.com/">
  <arg0 xsi:type="xsd:string">name</arg0>
  <arg1>
    <username xsi:type="xsd:string">username</username>
    <password xsi:type="xsd:string">0ac495f743a36cef9b0eaafa92ae08e21</password>
  </arg1>
  <arg2 xsi:type="xsd:string">email</arg2>
  <arg3 xsi:type="xsd:string">domain</arg3>
</ns1:insertuser>
");

$result=$client->send($msg, $endpoint);

print_r($result);
Martin Taleski
  • 6,033
  • 10
  • 40
  • 78