demo = $demo ? $demo : Configuration::get('ETIQUETAGE_RETURN_TEST'); $this->module_conf = unserialize(Configuration::get( 'ETIQUETAGE_RETURN_CONF', null, $this->context->shop->id_shop_group, $this->context->shop->id )); } public function l($string, $specific = false, $locale = null) { if (!$specific) { $specific = basename(__FILE__, '.php'); } if (class_exists('Translate')) { return Translate::getModuleTranslation(get_parent_class(), $string, $specific); } return parent::l($string, $specific); } private function _fillXML($params, &$sls_generate_label, &$document) { $requires_cdata = array( 'Description', 'instructions', 'commercialName', 'companyName', 'lastName', 'firstName', 'line0', 'line1', 'line2', 'line3', 'city' ); foreach ($params as $key => $value) { if (is_numeric($key)) { // only happens with articles $key = 'article'; } if (!is_array($value)) { if ($value) { if (in_array($key, $requires_cdata)) { $tmp_element = $document->createElement($key); $tmp_element->appendChild($document->createCDATASection($value)); } else { $tmp_element = $document->createElement($key, $value); } $sls_generate_label->appendChild($tmp_element); } } else { $new_child = $document->createElement($key); $sls_generate_label->appendChild($new_child); $this->_fillXML($value, $new_child, $document); } } } protected function _callWS($params) { $document = new DOMDocument('1.0', 'utf-8'); $document->formatOutput = true; $document->preserveWhiteSpace = true; $soap_envelope = $document->createElement('soap:Envelope'); $soap_envelope->setAttribute('xmlns:soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $soap_envelope->setAttribute('xmlns:sls', 'http://sls.ws.coliposte.fr'); $soap_body = $document->createElement('soap:Body'); $sls_generate_label = $document->createElement('sls:generateLabel'); $sls_generate_label_request = $document->createElement('generateLabelRequest'); $soap_envelope->appendChild($soap_body); $soap_body->appendChild($sls_generate_label); $sls_generate_label->appendChild($sls_generate_label_request); $document->appendChild($soap_envelope); $this->_fillXML($params, $sls_generate_label_request, $document); $request = $document->saveXML(); // var_dump($this->xmlpp($request));die; $this->origin_request = $request; $this->request = $request; $headers = array( 'Accept-Encoding: gzip,deflate', 'Content-Type: text/xml; charset="utf-8"', 'SOAPAction: ""' ); $webservice_url = array_key_exists('dev_mode', $this->module_conf) && $this->module_conf['dev_mode'] ? self::SCE_WS_TELINTRANS : self::SCE_WS; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_URL, $webservice_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_VERBOSE, true); // IF demo() ELSE webservice() ENDIF if ($this->demo) { $result = Tools::file_get_contents(dirname(__FILE__).'/../functions/raw_response.txt'); } else { $result = curl_exec($ch); } $this->raw_response = new SoColissimoCurlParser($result); $result = $this->xmldata($result); if ($result === false) { echo nl2br(print_r(curl_getinfo($ch), true)); echo 'Request'; print('
'.print_r(htmlentities($request, ENT_QUOTES, 'UTF-8'), true).''); echo 'cURL error number:'.curl_errno($ch).'\n