function process() { $communicator = new RequestInformationFromMBW(); //$communicator->startDebugging(); $products = DB::query("SELECT \"InternalItemID\" FROM \"Product\" WHERE AllowPurchase = 1;"); $xml = '<STOCK>'; foreach ($products as $product) { $xml .= '<PRODUCT><ProductNumber>' . $product["InternalItemID"] . '</ProductNumber></PRODUCT>'; } $xml = '<STOCK><PRODUCT><ProductNumber>a21m 607 04 720</ProductNumber></PRODUCT><PRODUCT><ProductID>4</ProductID></PRODUCT>'; $xml .= '</STOCK>'; print_r($xml); $outcome = $communicator->runXMLCommand($xml); if (isset($outcome->Product)) { foreach ($outcome->Product as $variation) { $product = DataObject::get_one("Product", "InternalItemID = '" . trim($variation->ProductNumber) . "'"); echo "GO " . $variation->ProductNumber; print_r($product); } } else { die("no products"); } print_r($outcome); }
/** * *@param String $xml - string of XML content *@param Boolean $returnRaw - if set to true, the raw return object will be returned... *@return XML Object / Object **/ public function runXMLCommand($xml, $returnRaw = false) { $success = false; $resultObject = null; $client = null; try { $client = new SoapClient(self::$url, self::$connection_credentials); } catch (SoapFault $fault) { $client = null; user_error("could not create soap client", E_USER_NOTICE); } if ($client) { $array = array_merge(self::$db_credentials, array("sParams" => $xml)); try { $resultObject = $client->gbCallCustomerBusinessLinkMethod($array); $success = true; } catch (SoapFault $fault) { if ($this->debug) { echo '<p style="color: red">Error Message:</p>'; echo $fault->getMessage(); } else { user_error("my crash", E_USER_WARNING); } } if ($this->debug) { echo '<hr /><hr /><hr /><p style="color: green">Request : </p><xmp>' . $this->replacer($client->__getLastRequest()) . '</xmp>'; echo '<h3>Results</h3>'; echo "<xmp>"; print_r($resultObject); echo "</xmp>"; } if ($success) { if ($returnRaw) { return $resultObject; } if ($resultObject->gbCallCustomerBusinessLinkMethodResult) { $xml = $resultObject->sResult; $xmlObj = simplexml_load_string($xml); return $xmlObj; //alternative way... if (!self::$xml_object) { self::$xml_object = new XML(); } return self::$xml_object->parse($xml, true); } else { //user_error("unexpected result", E_USER_WARNING); } } } return null; }