/** * @param \SimpleXMLElement $xml * * @return Box * @throws BpostInvalidValueException * @throws BpostNotImplementedException */ public static function createFromXML(\SimpleXMLElement $xml) { $box = new Box(); if (isset($xml->sender)) { $box->setSender(Sender::createFromXML($xml->sender->children('http://schema.post.be/shm/deepintegration/v3/common'))); } if (isset($xml->nationalBox)) { /** @var \SimpleXMLElement $nationalBoxData */ $nationalBoxData = $xml->nationalBox->children('http://schema.post.be/shm/deepintegration/v3/national'); // build classname based on the tag name $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName()); if ($nationalBoxData->getName() == 'at24-7') { $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\At247'; } if (!method_exists($className, 'createFromXML')) { throw new BpostNotImplementedException(); } $nationalBox = call_user_func(array($className, 'createFromXML'), $nationalBoxData); $box->setNationalBox($nationalBox); } if (isset($xml->internationalBox)) { /** @var \SimpleXMLElement $internationalBoxData */ $internationalBoxData = $xml->internationalBox->children('http://schema.post.be/shm/deepintegration/v3/international'); // build classname based on the tag name $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($internationalBoxData->getName()); if (!method_exists($className, 'createFromXML')) { var_dump($className); throw new BpostNotImplementedException(); } $internationalBox = call_user_func(array($className, 'createFromXML'), $internationalBoxData); $box->setInternationalBox($internationalBox); } if (isset($xml->remark) && $xml->remark != '') { $box->setRemark((string) $xml->remark); } if (isset($xml->additionalCustomerReference) && $xml->additionalCustomerReference != '') { $box->setAdditionalCustomerReference((string) $xml->additionalCustomerReference); } if (!empty($xml->barcode)) { $box->setBarcode((string) $xml->barcode); } if (isset($xml->status) && $xml->status != '') { $box->setStatus((string) $xml->status); } return $box; }
/** * Modify the status for an order. * * @param string $reference The reference for an order * @param string $status The new status, allowed values are: OPEN, PENDING, CANCELLED, COMPLETED, ON-HOLD or PRINTED * * @return bool * @throws BpostCurlException * @throws BpostInvalidResponseException * @throws BpostInvalidSelectionException * @throws BpostInvalidValueException */ public function modifyOrderStatus($reference, $status) { $status = strtoupper($status); if (!in_array($status, Box::getPossibleStatusValues())) { throw new BpostInvalidValueException('status', $status, Box::getPossibleStatusValues()); } $url = '/orders/' . $reference; $document = new \DOMDocument('1.0', 'utf-8'); $document->preserveWhiteSpace = false; $document->formatOutput = true; $orderUpdate = $document->createElement('orderUpdate'); $orderUpdate->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/'); $orderUpdate->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $orderUpdate->appendChild($document->createElement('status', $status)); $document->appendChild($orderUpdate); $headers = array('Content-type: application/vnd.bpost.shm-orderUpdate-v3+XML'); return $this->doCall($url, $document->saveXML(), $headers, 'POST', false) == ''; }
/** * @param \SimpleXMLElement $xml * * @return Order * @throws BpostXmlNoReferenceFoundException * @throws BpostNotImplementedException */ public static function createFromXML(\SimpleXMLElement $xml) { // @todo work with classmaps ... if (!isset($xml->reference)) { throw new BpostXmlNoReferenceFoundException(); } $order = new Order((string) $xml->reference); if (isset($xml->costCenter) && $xml->costCenter != '') { $order->setCostCenter((string) $xml->costCenter); } if (isset($xml->orderLine)) { foreach ($xml->orderLine as $orderLine) { $order->addLine(Line::createFromXML($orderLine)); } } if (isset($xml->box)) { foreach ($xml->box as $box) { $order->addBox(Box::createFromXML($box)); } } return $order; }