debug = false; $this->params = null; $this->ws = Configuration::get('SOFLEXIBILITE_WS'); $this->login = Configuration::get('SOFLEXIBILITE_LOGIN'); $this->password = Configuration::get('SOFLEXIBILITE_PASSWORD'); $this->options = array( 'trace' => true, 'exceptions' => true, 'soap_version' => 'SOAP_1_1', 'encoding' => 'utf-8' ); } /** * Call web service. * * @param $method * @param $params * @return bool|mixed|null */ private function call($method, $params) { ini_set('soap.wsdl_cache_enabled', 0); ini_set('soap.wsdl_cache_ttl', 0); libxml_disable_entity_loader(false); $options = $this->options; $debug = $this->debug; try { $client = new SoapClient($this->ws, $options); } catch (Exception $e) { if ($debug) { echo '
'.print_r(libxml_get_errors(), true)."\n".
                    var_dump(libxml_get_last_error())."\n".
                    $e->getMessage().
                    '
'; } return false; } try { $result = $client->__call($method, array($params)); } catch (SoapFault $fault) { if ($debug) { echo 'Request :
'.$client->__getLastRequest().'
Response :
'.$client->__getLastResponse().'
Error Message :
'.$fault->getMessage().'
\n'; echo $fault->getMessage().'\n'; } $result = null; } return ($result); } /** * Get the delivery mode available. * * @return array */ protected function getSelectedDeliveryMode() { $delivery_mode = array(); $relay_carrier = new Carrier((int)Configuration::get('SOFLEXIBILITE_A2P_ID')); $bpr_carrier = new Carrier((int)Configuration::get('SOFLEXIBILITE_BPR_ID')); if (Validate::isLoadedObject($relay_carrier) && $relay_carrier->active) { $delivery_mode = array_merge($delivery_mode, array('A2P', 'CMT')); } if (Validate::isLoadedObject($bpr_carrier) && $bpr_carrier->active) { $delivery_mode = array_merge($delivery_mode, array('BPR', 'BDP', 'CDI')); } return ($delivery_mode); } /** * Get a list of relay pickup based on the address. * * @param $address * @param int $filter_relay Filter relay pickup, set 0 not to get PickUp relays * @return bool|mixed|null */ public function getRelays($address, $filter_relay = 1) { $method = 'findRDVPointRetraitAcheminement'; $request_id = md5(date('Ymdhis')); if (isset($address['country']) && Tools::strlen($address['country']) > 2) { $address['country'] = Country::getIsoById((int)Country::getIdByName(null, $address['country'])); } $params = array( 'accountNumber' => $this->login, 'password' => $this->password, 'address' => $this->cleanup($address['address']), 'zipCode' => sprintf('%s', ($address['postcode'])), 'city' => $this->cleanup($address['city']), 'countryCode' => (isset($address['country']) && $address['country']) ? $address['country'] : 'FR', 'optionInter' => (isset($address['country']) && !in_array($address['country'], array('FR'))) ? 1 : 0, 'weight' => $address['weight'], 'shippingDate' => $address['date'], 'filterRelay' => (int)$filter_relay, 'requestId' => $request_id.$request_id ); return ($this->call($method, $params)); } /** * Get Information about a relay based on its ID. * * @param $id * @param string|null $date * @return stdClass|null */ public function getRelay($id, $date = null) { $method = 'findPointRetraitAcheminementByID'; if (!$date) { $date = date('d/m/Y', time() + 86400 * 2); } $params = array( 'accountNumber' => $this->login, 'password' => $this->password, 'id' => $id, 'date' => $date ); $result = $this->call($method, $params); if (!$result->return->errorCode) { return ($result->return->pointRetraitAcheminement); } else { return null; } } /** * Get Information about a relay based on its ID. * Static function. * * @param $id * @param string|null $date * @return stdClass|null */ public static function getRelayStatic($id, $date = null) { $web_service = new SoFlexibiliteWebService(); return $web_service->getRelay($id, $date); } /** * Santize string for web service call * * @param $text * @return string */ private function cleanup($text) { $text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8'); $text = preg_replace( array('/ß/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('ss', '$1', '$1e', '$1'), $text ); $text = str_replace('_', '/', $text); $text = preg_replace('/[\x00-\x1F\x21-\x2E\x3A-\x3F\x5B-\x60\x7B-\x7F]/', ' ', $text); return (Tools::strtoupper($text)); } }