0

The following Soap Request works when the ORDER element is submitted as single element as an array or as an object, however I need to have multiple ORDER elements. I am now trying SoapParam/SoapVar with no luck at all. days of attempts to get this working at this point. Thank you all for your time!

function SendOrder($wan, $param) {

  $url = "someurl";

  $options = array(
    "trace"      => 1,
    "exceptions" => 1,
    "cache_wsdl"    => WSDL_CACHE_NONE
  );

  try {
    $client = new SoapClient($url, $options);

    $xmlR = $client->ORDER($param);
    //create a usable array
    $json = json_encode($xmlR);
    $array = json_decode($json,true);
    dump($client->__getLastRequestHeaders());
    dump($client->__getLastRequest());
    dump($client->__getLastResponseHeaders());
    dump($client->__getLastResponse());
    return $array;

  } catch (\Exception $e) {
    return $e;
  }
};

$param = new stdClass;
$param->REQUESTUNIQUEID = uniqid();

$person = 0;
$a = 0;
$orders = new stdClass;

foreach ($_SESSION['cartR'] as $c) {
  $person++;
  $menu_item = new stdClass;
  $menu_item->PERSON = array('_' => "{$c->for_who}", 'NUMBER' => $person);
  $menu_item->SERVICETIME = $service_time;
  $menu_item->MENUITEM = array('_' => '', 'ID' => $c->product_id);
  $menu_item->QUANTITY = 1;
  $menu_item->PRICE = $c->price;
  $menu_item->TOPPINGPART = "Whole";
  $menu_item->ITEMLEVEL = 0;
  $menu_item->POSWINDOW = array('_' => 'test', 'ID' => "");

  $orders->MENUTIEM = $menu_item;
  $param->ORDERS[] = $orders;
  unset($menu_item);
}

$result = SendOrder($wan, $param);

Produces an object:

object(stdClass)#26 (13) {
 ["REQUESTUNIQUEID"]=>
 string(13) "5c829ff8197fb"

 ["ORDERS"]=>
  array(5) {
    [0]=>
    object(stdClass)#26 (1) {
      ["MENUTIEM"]=>
      object(stdClass)#39 (6) {
        ["PERSON"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["NUMBER"]=>
          int(5)
        }
        ["SERVICETIME"]=>
        string(20) "0001-01-01T00:00:00Z"
        ["MENUITEM"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["ID"]=>
          int(8001)
        }
        ["QUANTITY"]=>
        int(1)
        ["PRICE"]=>
        string(4) "2.50"
        ["ITEMLEVEL"]=>
        int(0)
      }
    }
    [1]=>
    object(stdClass)#26 (1) {
      ["MENUTIEM"]=>
      object(stdClass)#39 (6) {
        ["PERSON"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["NUMBER"]=>
          int(5)
        }
        ["SERVICETIME"]=>
        string(20) "0001-01-01T00:00:00Z"
        ["MENUITEM"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["ID"]=>
          int(8001)
        }
        ["QUANTITY"]=>
        int(1)
        ["PRICE"]=>
        string(4) "2.50"
        ["ITEMLEVEL"]=>
        int(0)
      }
    }
    [2]=>
    object(stdClass)#26 (1) {
      ["MENUTIEM"]=>
      object(stdClass)#39 (6) {
        ["PERSON"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["NUMBER"]=>
          int(5)
        }
        ["SERVICETIME"]=>
        string(20) "0001-01-01T00:00:00Z"
        ["MENUITEM"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["ID"]=>
          int(8001)
        }
        ["QUANTITY"]=>
        int(1)
        ["PRICE"]=>
        string(4) "2.50"
        ["ITEMLEVEL"]=>
        int(0)
      }
    }
    [3]=>
    object(stdClass)#26 (1) {
      ["MENUTIEM"]=>
      object(stdClass)#39 (6) {
        ["PERSON"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["NUMBER"]=>
          int(5)
        }
        ["SERVICETIME"]=>
        string(20) "0001-01-01T00:00:00Z"
        ["MENUITEM"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["ID"]=>
          int(8001)
        }
        ["QUANTITY"]=>
        int(1)
        ["PRICE"]=>
        string(4) "2.50"
        ["ITEMLEVEL"]=>
        int(0)
      }
    }
    [4]=>
    object(stdClass)#26 (1) {
      ["MENUTIEM"]=>
      object(stdClass)#39 (6) {
        ["PERSON"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["NUMBER"]=>
          int(5)
        }
        ["SERVICETIME"]=>
        string(20) "0001-01-01T00:00:00Z"
        ["MENUITEM"]=>
        array(2) {
          ["_"]=>
          string(0) ""
          ["ID"]=>
          int(8001)
        }
        ["QUANTITY"]=>
        int(1)
        ["PRICE"]=>
        string(4) "2.50"
        ["ITEMLEVEL"]=>
        int(0)
      }
    }
  }
    }

I attempted suggestions in Stack OVerflow 3617398 and a few others. I am attempting SoapVar and SoapParam with no success at all, not even getting a trimmed down request of the minimal required elements through.

How do I get the Object created/formated properly with multiple elements with the same name in this scenario?

RESULT WITH THE ARRAY:

"
string(229) "HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 18:57:11 GMT
Content-Length: 671
"
string(671) "5c82bb00d12a1 Web Service 27.4.3.320 Error false 0"

SOAPVAR AND SOAPPARAM (I am trying different combinations of SoapParam and SoapVar with the minimium required elements same url and same options as above)

$unique_id = uniqid();

$client_software = new stdClass;
  $client_software->SOFTWARENAME  = 'company name';
  $client_software->SOFTWAREAPIVERSION = 1;
  $client_software->SOFTWARECODEVERSION = "1.0.0.0"

$client = new SoapClient($url, $options);

$xmlR = $client->CHECKIMPORT(
new SoapParam(new SoapVar($unique_id, XSD_STRING), 'REQUESTUNIQUEID'),
new SoapParam(new SoapVar($client_software, SOAP_ENC_OBJECT), 'CLIENTSOFTWARE'),

    );

RESPONSE:

Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 08 Mar 2019 19:06:03 GMT
Content-Length: 868
"
string(868) "Web Service 27.4.3.320 REQUESTUNIQUEID is missing. CLIENTSOFTWARE is missing. false 0

WSDL Tree

    <s:element minOccurs="0" maxOccurs="1" name="ORDERS" type="tns:IMPORTORDERLIST"/>

<s:complexType name="IMPORTORDERLIST">
   <s:choice minOccurs="0" maxOccurs="unbounded">
     <s:element minOccurs="1" maxOccurs="1" name="DISCOUNT" nillable="true" type="tns:IMPORTDISCOUNT"/>
     <s:element minOccurs="1" maxOccurs="1" name="CHARGE" nillable="true" type="tns:IMPORTCHARGE"/>
     <s:element minOccurs="1" maxOccurs="1" name="INSTRUCTION" nillable="true" type="tns:IMPORTINSTRUCTIONS"/>
     <s:element minOccurs="1" maxOccurs="1" name="MENUITEM" nillable="true" type="tns:IMPORTMENUITEM"/>

  • What is the result you get? "No luck at all" does not provide a lot of information. You say it works when you have a single order, do you mean the same structure but with an array of size 1, or getting rid of the array altogether? – miken32 Mar 08 '19 at 18:27
  • And what is `$soap_param`? – miken32 Mar 08 '19 at 18:28
  • sorry, $soap_param should have been $param. (corrected in the post) – Jeff Petersen Mar 08 '19 at 18:56
  • Yes the code works when I submit a single ORDER element where ORDER is a multi-dimensional associative array of 1 Order. – Jeff Petersen Mar 08 '19 at 19:23
  • And does the API say that `ORDERS` is a valid element and is supposed to contain multiple child elements? You can't just make these things up... – miken32 Mar 08 '19 at 19:31
  • Yes. ORDERS: Optional. Type: ORDER list. Contains zero or more ORDER elements. See below. below: A check import can have zero or more orders. If no orders are added, the orders element will be empty. The most common order is a menu item. – Jeff Petersen Mar 08 '19 at 19:38
  • Ok; I don't see any mention of `ORDER` elements in your code. It looks like your `ORDERS` element contains zero or more `MENUITEM` elements. – miken32 Mar 08 '19 at 19:40
  • $param->ORDERS[] = $orders; produces the array of 5 ORDERS elements ["ORDERS"]=> array(5) {. I think their ommision of the "S" on Order is in error. as none of the sample code has an ORDER element they are all ORDERS. Even in the wsdl document tree there is no mention of an ORDER element just ORDERS – Jeff Petersen Mar 08 '19 at 19:51
  • 1
    `ORDERS` !== `ORDER` – miken32 Mar 08 '19 at 19:51
  • added the WSDL documentation to the post. nowhere is there an ORDER element. Giving it a try just to be sure. – Jeff Petersen Mar 08 '19 at 20:01
  • created the array as ORDERS => ORDER=>array(5) { [ ] =>MENUITEM=>... details. wasn't it either. – – Jeff Petersen Mar 08 '19 at 20:26

0 Answers0