Merge branch 'ticket-10580-LaPosteWSU'
This commit is contained in:
commit
6c12b392eb
@ -104,6 +104,11 @@ class LaPosteWS extends Module {
|
||||
Configuration::updateValue('LAPOSTEWS_CONTRACT', Tools::getValue('contract'));
|
||||
Configuration::updateValue('LAPOSTEWS_API_PASSWORD', Tools::getValue('apipassword'));
|
||||
Configuration::updateValue('LAPOSTEWS_API_CONTRACT', Tools::getValue('apicontract'));
|
||||
// Configuration::updateValue('LAPOSTEWS_API_PASSWORD2', Tools::getValue('apipassword2'));
|
||||
// Configuration::updateValue('LAPOSTEWS_API_CONTRACT2', Tools::getValue('apicontract2'));
|
||||
// Configuration::updateValue('LAPOSTEWS_API_PASSWORD_WSU', Tools::getValue('apipassword_wsu'));
|
||||
// Configuration::updateValue('LAPOSTEWS_API_CONTRACT_WSU', Tools::getValue('apicontract_wsu'));
|
||||
// Configuration::updateValue('LAPOSTEWS_WSU_ENABLE', Tools::getValue('mode_wsu'));
|
||||
Configuration::updateValue('LAPOSTEWS_MODE', Tools::getValue('mode'));
|
||||
Configuration::updateValue('LAPOSTEWS_COMMERCIALNAME', Tools::getValue('commercialname'));
|
||||
Configuration::updateValue('LAPOSTEWS_SHIPPING_SITE', Tools::getValue('shippingsite'));
|
||||
@ -158,11 +163,32 @@ class LaPosteWS extends Module {
|
||||
<label for="apipassword">'.$this->l('Password:').'</label>
|
||||
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD').'" id="apipassword" name="apipassword" />
|
||||
</p>
|
||||
<p class="text">
|
||||
<label for="apicontract2">'.$this->l('Contract number:').' INTER</label>
|
||||
<input type="text" value="'.Configuration::get('LAPOSTEWS_API_CONTRACT2').'" id="apicontract2" name="apicontract2" />
|
||||
</p>
|
||||
<p class="text">
|
||||
<label for="apipassword2">'.$this->l('Password:').' INTER</label>
|
||||
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD2').'" id="apipassword2" name="apipassword2" />
|
||||
</p>
|
||||
<p class="text">
|
||||
<label for="apicontract_wsu">'.$this->l('Contract number:').' WSU</label>
|
||||
<input type="text" value="'.Configuration::get('LAPOSTEWS_API_CONTRACT_WSU').'" id="apicontract_wsu" name="apicontract_wsu" />
|
||||
</p>
|
||||
<p class="text">
|
||||
<label for="apipassword_wsu">'.$this->l('Password:').' WSU</label>
|
||||
<input type="password" value="'.Configuration::get('LAPOSTEWS_API_PASSWORD_WSU').'" id="apipassword_wsu" name="apipassword_wsu" />
|
||||
</p>
|
||||
<p class="radio">
|
||||
<span style="font-weight: bold; float: left; text-align: right; width: 200px; padding: 0.2em 0.5em 0 0;">'.$this->l('Mode:').'</span>
|
||||
<input type="radio" name="mode" id="mode_0" value="0"'.(Configuration::get('LAPOSTEWS_MODE')? '': ' checked="checked"').' /> <label for="mode_0" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('Test').'</label>
|
||||
<input type="radio" name="mode" id="mode_1" value="1"'.(Configuration::get('LAPOSTEWS_MODE')? ' checked="checked"': '').' /> <label for="mode_1" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('Production').'</label>
|
||||
</p>
|
||||
<p class="radio">
|
||||
<span style="font-weight: bold; float: left; text-align: right; width: 200px; padding: 0.2em 0.5em 0 0;">'.$this->l('Mode WSU:').'</span>
|
||||
<input type="radio" name="mode_wsu" id="mode_wsu_0" value="1"'.((int)Configuration::get('LAPOSTEWS_WSU_ENABLE')==0? '': ' checked="checked"').' /> <label for="mode_wsu_0" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('activé').'</label>
|
||||
<input type="radio" name="mode_wsu" id="mode_wsu_1" value="0"'.((int)Configuration::get('LAPOSTEWS_WSU_ENABLE')==0? ' checked="checked"': '').' /> <label for="mode_wsu_1" style="float: none; margin-right: 20px; font-weight: normal; width: auto;">'.$this->l('desactivé').'</label>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<br />
|
||||
|
@ -3,7 +3,11 @@ if(!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
include dirname(__FILE__).'/webservice.php';
|
||||
if((int)Configuration::get('LAPOSTEWS_WSU_ENABLE') == 1) {
|
||||
include dirname(__FILE__).'/webservice_wsu.php';
|
||||
} else {
|
||||
include dirname(__FILE__).'/webservice.php';
|
||||
}
|
||||
|
||||
|
||||
global $laposte_formats;
|
||||
@ -665,73 +669,64 @@ class LaposteCarrier {
|
||||
|
||||
$products_names = array();
|
||||
|
||||
/*if(!in_array((int) Db::getInstance()->getValue('
|
||||
SELECT `id_country`
|
||||
FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_address` = '.(int) $order->id_address_delivery.'
|
||||
'), array(3, 9))) {
|
||||
// If the address is not in France or Belgium, add products for the CN23
|
||||
$customs_details = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `id_order_detail`, `product_name`, `product_weight`, ROUND((product_price * (1 - reduction_percent / 100) - reduction_amount) * (1 - group_reduction / 100) * (1 + tax_rate / 100), 6) AS `product_price`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `id_order_detail` IN ('.implode(', ', array_keys($products)).')
|
||||
') as $p) {
|
||||
$products_names[(int) $p['id_order_detail']] = $p;
|
||||
}
|
||||
|
||||
foreach($products as $k => $v) {
|
||||
if($v > 0) {
|
||||
$parcel->addArticle(
|
||||
$customs_details[$k]['product_name'],
|
||||
$v,
|
||||
$customs_details[$k]['product_weight'],
|
||||
$customs_details[$k]['product_price'],
|
||||
'' // TODO
|
||||
);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*if($_SERVER['REMOTE_ADDR'] != '78.226.56.137' && !in_array((int) $cookie->id_employee, array(70, 77)) && Db::getInstance()->getRow('
|
||||
SELECT a.`id_country`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a
|
||||
ON o.`id_address_delivery` = a.`id_address`
|
||||
WHERE a.`id_country` != 8
|
||||
AND o.`id_order` = '.(int) $order->id.'
|
||||
')) {
|
||||
return array('<p class="error">Impression d\'une étiquette de livraison vers l\'étranger impossible</p>', false);
|
||||
}*/
|
||||
|
||||
$result = $parcel->send();
|
||||
|
||||
if(!$result || $result && (get_class($result) == 'SoapFault')) {
|
||||
$html .= '<p class="error">'.$this->l('An error happened during the parcel registration process').'</p><br />';
|
||||
} else {
|
||||
if(isset($result->getLetterColissimoReturn) && $result->getLetterColissimoReturn->errorID != 0 && ((string) $result->getLetterColissimoReturn->error) != '') {
|
||||
$html .= '<p class="error">'.$result->getLetterColissimoReturn->error.'</p><br />';
|
||||
} elseif(isset($result->genererEtiquetteBic3Response) && ($result->genererEtiquetteBic3Response->message->type) == 'ERROR') {
|
||||
$html .= '<p class="error">'.$result->genererEtiquetteBic3Response->message->libelle.'</p><br />';
|
||||
/**
|
||||
* @Override laposte WSU
|
||||
*/
|
||||
if((int)Configuration::get('LAPOSTEWS_WSU_ENABLE') == 1) {
|
||||
if(!$result || !is_array($result) && get_class($result) == 'SoapFault' || !$result['data']) {
|
||||
$html .= '<p class="error">'.$this->l('An error happened during the parcel registration process').'</p><br />';
|
||||
} else {
|
||||
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223' && $_SERVER['REMOTE_ADDR'] != '37.160.139.229') {
|
||||
$socolissimo_carrier = Db::getInstance()->getRow('
|
||||
SELECT `id_carrier`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `external_module_name` = "socolissimo"
|
||||
AND `deleted` = 0
|
||||
ORDER BY `id_carrier` DESC
|
||||
');
|
||||
if(isset($result['data']->messages->type) && $result['data']->messages->type == 'ERROR') {
|
||||
$html .= '<p class="error">'.strip_tags((string) $result['data']->messages->messageContent).'</p><br />';
|
||||
} else {
|
||||
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223' && $_SERVER['REMOTE_ADDR'] != '37.160.139.229') {
|
||||
$socolissimo_carrier = Db::getInstance()->getRow('
|
||||
SELECT `id_carrier`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `external_module_name` = "socolissimo"
|
||||
AND `deleted` = 0
|
||||
ORDER BY `id_carrier` DESC
|
||||
');
|
||||
|
||||
if(isset($result->genererEtiquetteBic3Response)) {
|
||||
$order->shipping_number = $result->genererEtiquetteBic3Response->parcelNumber;
|
||||
} else {
|
||||
$order->shipping_number = $result->getLetterColissimoReturn->parcelNumber;
|
||||
$order->shipping_number = $result['data']->labelResponse->parcelNumber;
|
||||
|
||||
if($socolissimo_carrier) {
|
||||
$order->id_carrier_shipping = (int) $socolissimo_carrier['id_carrier'];
|
||||
}
|
||||
$order->update();
|
||||
}
|
||||
if($socolissimo_carrier) {
|
||||
$order->id_carrier_shipping = (int) $socolissimo_carrier['id_carrier'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!$result || $result && (get_class($result) == 'SoapFault')) {
|
||||
$html .= '<p class="error">'.$this->l('An error happened during the parcel registration process').'</p><br />';
|
||||
} else {
|
||||
if(isset($result->getLetterColissimoReturn) && $result->getLetterColissimoReturn->errorID != 0 && ((string) $result->getLetterColissimoReturn->error) != '') {
|
||||
$html .= '<p class="error">'.$result->getLetterColissimoReturn->error.'</p><br />';
|
||||
} elseif(isset($result->genererEtiquetteBic3Response) && ($result->genererEtiquetteBic3Response->message->type) == 'ERROR') {
|
||||
$html .= '<p class="error">'.$result->genererEtiquetteBic3Response->message->libelle.'</p><br />';
|
||||
} else {
|
||||
if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223' && $_SERVER['REMOTE_ADDR'] != '37.160.139.229') {
|
||||
$socolissimo_carrier = Db::getInstance()->getRow('
|
||||
SELECT `id_carrier`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `external_module_name` = "socolissimo"
|
||||
AND `deleted` = 0
|
||||
ORDER BY `id_carrier` DESC
|
||||
');
|
||||
|
||||
if(isset($result->genererEtiquetteBic3Response)) {
|
||||
$order->shipping_number = $result->genererEtiquetteBic3Response->parcelNumber;
|
||||
} else {
|
||||
$order->shipping_number = $result->getLetterColissimoReturn->parcelNumber;
|
||||
}
|
||||
if($socolissimo_carrier) {
|
||||
$order->id_carrier_shipping = (int) $socolissimo_carrier['id_carrier'];
|
||||
}
|
||||
$order->update();
|
||||
}
|
||||
$order->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -742,6 +737,13 @@ class LaposteCarrier {
|
||||
public function renderLabel($order, $weight, $shipping_data) {
|
||||
global $cookie, $laposte_formats;
|
||||
|
||||
/**
|
||||
* @Override laposte WSU
|
||||
*/
|
||||
if((int)Configuration::get('LAPOSTEWS_WSU_ENABLE') == 1) {
|
||||
return $shipping_date['label'];
|
||||
}
|
||||
|
||||
$id_order = (int) $order->id;
|
||||
$weight = 0.24;
|
||||
|
||||
@ -1359,7 +1361,7 @@ class LaposteCarrier {
|
||||
),
|
||||
$laposte_formats['BELG']
|
||||
);
|
||||
//mail('perron@antadis.com', 'test belg', $shipping_data->genererEtiquetteBic3Response->xmlResponse->zoneRoutage->zoneCABRoutage->codeBarreRoutage);
|
||||
//mail('perron@antadis.com', 'test belg', $shipping_data->genererEtiquetteBic3Response->xmlResponse->zoneRoutage->zoneCABRoutage->codeBarreRoutage);
|
||||
} else {
|
||||
$format = str_replace(
|
||||
array(
|
||||
@ -1453,21 +1455,25 @@ class LaposteCarrier {
|
||||
public function logParcel($shipping_data, $products) {
|
||||
global $cookie;
|
||||
|
||||
/*$id_carrier = Db::getInstance()->getValue('
|
||||
SELECT MAX(`id_carrier`)
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `external_module` = "socolissimo"
|
||||
AND `active` = 1
|
||||
AND `deleted` = 0
|
||||
');
|
||||
|
||||
$order_date = strtotime(Db::getInstance()->getValue('
|
||||
SELECT MIN(`date_add`)
|
||||
FROM `'._DB_PREFIX_.'order_history`
|
||||
WHERE `id_order` = '.(int) Tools::getValue('id_order').'
|
||||
AND `id_order_state` = 2
|
||||
OR `id_order_state` = 17
|
||||
'));*/
|
||||
/**
|
||||
* @Override laposte WSU
|
||||
*/
|
||||
if((int)Configuration::get('LAPOSTEWS_WSU_ENABLE') == 1) {
|
||||
foreach($products as $k => $v) {
|
||||
if($v > 0) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT `'._DB_PREFIX_.'lapostews` VALUES (
|
||||
'.(int) $k.',
|
||||
'.(int) $cookie->id_employee.',
|
||||
'.(int) $v.',
|
||||
"'.pSQL($shipping_data['data']->labelResponse->parcelNumber).'",
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($shipping_data->getLetterColissimoReturn)) {
|
||||
foreach($products as $k => $v) {
|
||||
@ -1481,39 +1487,6 @@ class LaposteCarrier {
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
|
||||
/*$log_order = Db::getInstance()->getRow('
|
||||
SELECT `delay`, `quantity` - `quantity_canceled` - `quantity_sent` AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'logistics_order`
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
');
|
||||
|
||||
$partially_late = (bool) (int) Db::getInstance()->getRow('
|
||||
SELECT `id_order_detail`
|
||||
FROM `'._DB_PREFIX_.'logistics_parcel`
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
AND `on_time` = 1
|
||||
');
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'logistics_parcel` VALUES (
|
||||
'.(int) $k.',
|
||||
'.(int) $v.',
|
||||
'.(int) $cookie->id_employee.',
|
||||
"laposte",
|
||||
'.(int) $id_carrier.',
|
||||
"'.pSQL($shipping_data->getLetterColissimoReturn->parcelNumber).'",
|
||||
NOW(),
|
||||
'.(time() < $order_date + ((int) $log_order['delay'] * 86400)? 1: 2).'
|
||||
)
|
||||
');
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'logistics_order`
|
||||
SET `quantity_sent` = `quantity_sent` + '.(int) $v.'
|
||||
'.((int) $log_order['quantity'] - $v <= 0? ', `on_time` = '.(time() < $order_date + ((int) $log_order['delay'] * 86400)? 1: ($partially_late? 3: 2)): '').'
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
');*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1528,39 +1501,6 @@ class LaposteCarrier {
|
||||
NOW()
|
||||
)
|
||||
');
|
||||
|
||||
/*$log_order = Db::getInstance()->getRow('
|
||||
SELECT `delay`, `quantity` - `quantity_canceled` - `quantity_sent` AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'logistics_order`
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
');
|
||||
|
||||
$partially_late = (bool) (int) Db::getInstance()->getRow('
|
||||
SELECT `id_order_detail`
|
||||
FROM `'._DB_PREFIX_.'logistics_parcel`
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
AND `on_time` = 1
|
||||
');
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'logistics_parcel` VALUES (
|
||||
'.(int) $k.',
|
||||
'.(int) $v.',
|
||||
'.(int) $cookie->id_employee.',
|
||||
"laposte",
|
||||
'.(int) $id_carrier.',
|
||||
"'.pSQL($shipping_data->genererEtiquetteBic3Response->parcelNumber).'",
|
||||
NOW(),
|
||||
'.(time() < $order_date + ((int) $log_order['delay'] * 86400)? 1: 2).'
|
||||
)
|
||||
');
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'logistics_order`
|
||||
SET `quantity_sent` = `quantity_sent` + '.(int) $v.'
|
||||
'.((int) $log_order['quantity'] - $v <= 0? ', `on_time` = '.(time() < $order_date + ((int) $log_order['delay'] * 86400)? 1: ($partially_late? 3: 2)): '').'
|
||||
WHERE `id_order_detail` = '.(int) $k.'
|
||||
');*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1583,10 +1523,17 @@ class LaposteCarrier {
|
||||
$content_txt = 'Contenu du colis :';
|
||||
}
|
||||
|
||||
if(isset($shipping_data->genererEtiquetteBic3Response)) {
|
||||
$shipping_number = $shipping_data->genererEtiquetteBic3Response->parcelNumber;
|
||||
/**
|
||||
* @Override laposte WSU
|
||||
*/
|
||||
if((int)Configuration::get('LAPOSTEWS_WSU_ENABLE') == 1) {
|
||||
$shipping_number = $shipping_data['data']->labelResponse->parcelNumber;
|
||||
} else {
|
||||
$shipping_number = $shipping_data->getLetterColissimoReturn->parcelNumber;
|
||||
if(isset($shipping_data->genererEtiquetteBic3Response)) {
|
||||
$shipping_number = $shipping_data->genererEtiquetteBic3Response->parcelNumber;
|
||||
} else {
|
||||
$shipping_number = $shipping_data->getLetterColissimoReturn->parcelNumber;
|
||||
}
|
||||
}
|
||||
|
||||
$templateVars = array(
|
||||
|
446
modules/logistics/carriers/laposte/webservice_wsu.php
Normal file
446
modules/logistics/carriers/laposte/webservice_wsu.php
Normal file
@ -0,0 +1,446 @@
|
||||
<?php
|
||||
if(!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class SoapResponse {
|
||||
|
||||
const CONTENT_TYPE = 'Content-Type: application/xop+xml;';
|
||||
const UUID = '/--uuid:/'; //This is the separator of each part of the response
|
||||
const CONTENT = 'Content-';
|
||||
|
||||
public $attachments = array ();
|
||||
public $soapResponse = array ();
|
||||
public $uuid = NULL;
|
||||
|
||||
public function __construct($response)
|
||||
{
|
||||
if(strpos($response, self::CONTENT_TYPE ) !== FALSE) {
|
||||
$this->parseResponse($response);
|
||||
} else {
|
||||
throw new Exception('This response is not '.self::CONTENT_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseResponse($response)
|
||||
{
|
||||
$content = array ();
|
||||
$matches = array ();
|
||||
preg_match_all(self::UUID, $response, $matches, PREG_OFFSET_CAPTURE);
|
||||
for($i = 0; $i < count ($matches[0]) - 1; $i++) {
|
||||
if ($i + 1 < count ( $matches [0] )) {
|
||||
$content[$i] = substr($response, $matches[0][$i][1], $matches[0][$i + 1][1] - $matches[0][$i][1]);
|
||||
} else {
|
||||
$content[$i] = substr($response, $matches[0][$i][1], strlen($response));
|
||||
}
|
||||
}
|
||||
foreach ( $content as $part ) {
|
||||
if($this->uuid == NULL){
|
||||
$uuidStart = 0;
|
||||
$uuidEnd = 0;
|
||||
$uuidStart = strpos($part, self::UUID, 0) + strlen(self::UUID);
|
||||
$uuidEnd = strpos($part, "\r\n", $uuidStart);
|
||||
$this->uuid = substr($part, $uuidStart, $uuidEnd-$uuidStart);
|
||||
}
|
||||
$header = $this->extractHeader($part);
|
||||
if(count($header) > 0){
|
||||
if(strpos($header['Content-Type'], 'type="text/xml"') !== FALSE) {
|
||||
$this->soapResponse['header'] = $header;
|
||||
$this->soapResponse['data'] = trim(substr($part, $header['offsetEnd']));
|
||||
} else {
|
||||
$attachment['header'] = $header;
|
||||
$attachment['data'] = trim(substr($part, $header['offsetEnd']));
|
||||
array_push($this->attachments, $attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the header from the Web Service response
|
||||
* @param string $part
|
||||
* @return array $header
|
||||
*/
|
||||
private function extractHeader($part)
|
||||
{
|
||||
$header = array();
|
||||
$headerLineStart = strpos($part, self::CONTENT, 0);
|
||||
$endLine = 0;
|
||||
while($headerLineStart !== FALSE){
|
||||
$header['offsetStart'] = $headerLineStart;
|
||||
$endLine = strpos($part, "\r\n", $headerLineStart);
|
||||
$headerLine = explode(': ', substr($part, $headerLineStart, $endLine - $headerLineStart));
|
||||
$header[$headerLine[0]] = $headerLine[1];
|
||||
$headerLineStart = strpos($part, self::CONTENT, $endLine);
|
||||
}
|
||||
$header['offsetEnd'] = $endLine;
|
||||
return $header;
|
||||
}
|
||||
}
|
||||
|
||||
class Parcel {
|
||||
|
||||
public function addArticle($description, $qty, $weight, $value, $wco_nom) {}
|
||||
|
||||
public function getShippingNumber() {}
|
||||
|
||||
public function attachOrder($id_order)
|
||||
{
|
||||
$this->order = new Order($id_order);
|
||||
|
||||
if(Validate::isLoadedObject($this->order)) {
|
||||
$this->product_type = '';
|
||||
|
||||
$dst_customer = new Customer($this->order->id_customer);
|
||||
$dst_address = new Address($this->order->id_address_delivery);
|
||||
$dst_country = new Country($dst_address->id_country);
|
||||
|
||||
$langs = array(
|
||||
1 => 'EN',
|
||||
2 => 'FR',
|
||||
3 => 'ES',
|
||||
5 => 'IT',
|
||||
6 => 'EN',
|
||||
);
|
||||
|
||||
$this->dst_address = array(
|
||||
'companyName' => '',
|
||||
'lastName' => '',
|
||||
'firstName' => '',
|
||||
'line0' => '',
|
||||
'line1' => '',
|
||||
'line2' => '',
|
||||
'line3' => '',
|
||||
'countryCode' => '',
|
||||
'city' => '',
|
||||
'zipCode' => '',
|
||||
'phoneNumber' => '',
|
||||
'mobileNumber' => '',
|
||||
'doorCode1' => '',
|
||||
'doorCode2' => '',
|
||||
'email' => '',
|
||||
'intercom' => '',
|
||||
'language' => $langs[(int) $this->order->id_lang],
|
||||
);
|
||||
|
||||
$this->prid = '';
|
||||
$this->instructions = '';
|
||||
|
||||
$unicode_ack = json_decode('"\u0006"');
|
||||
$unicode_ack2 = json_decode('"\u00ad"');
|
||||
|
||||
if(Module::isInstalled('socolissimo')
|
||||
&& ($so_data = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||||
WHERE `id_cart` = '.(int) $this->order->id_cart.'
|
||||
AND `id_customer` = '.(int) $this->order->id_customer.'
|
||||
'))
|
||||
&& (
|
||||
(strpos(Db::getInstance()->getValue('
|
||||
SELECT `name`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `id_carrier` = '.(int) $this->order->id_carrier.'
|
||||
'), 'La Poste') !== FALSE)
|
||||
|| (strpos(Db::getInstance()->getValue('
|
||||
SELECT `name`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `id_carrier` = '.(int) $this->order->id_carrier.'
|
||||
'), 'Colissimo') !== FALSE)
|
||||
)) {
|
||||
$this->product_type = $so_data['delivery_mode'];
|
||||
if($this->product_type == 'BOM') {
|
||||
$this->product_type = 'DOM';
|
||||
}
|
||||
|
||||
$this->dst_address['email'] = $so_data['ceemail'];
|
||||
if(empty($this->dst_address['email'])) {
|
||||
$this->dst_address['email'] = $dst_customer->email;
|
||||
}
|
||||
|
||||
if(!empty($so_data['cename'])) {
|
||||
$this->dst_address['lastName'] = mb_substr($so_data['cename'], 0, 35);
|
||||
} else {
|
||||
$this->dst_address['lastName'] = mb_substr($so_data['prname'], 0, 35);
|
||||
}
|
||||
|
||||
if(!empty($so_data['cefirstname'])) {
|
||||
$this->dst_address['firstName'] = mb_substr(str_replace('', ' ', $so_data['cefirstname']), 0, 29);
|
||||
} else {
|
||||
$this->dst_address['firstName'] = mb_substr(str_replace('', ' ', $so_data['prfirstname']), 0, 29);
|
||||
}
|
||||
|
||||
$address_lines = array();
|
||||
for($i = 1; $i < 5; $i++) {
|
||||
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
|
||||
$address_lines[] = trim($line);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($address_lines) == 1) {
|
||||
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[0]);
|
||||
} elseif(count($address_lines) == 2) {
|
||||
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[0]);
|
||||
$this->dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[1]);
|
||||
} elseif(count($address_lines) == 3) {
|
||||
$this->dst_address['line0'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[0]);
|
||||
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[1]);
|
||||
$this->dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[2]);
|
||||
} else {
|
||||
$this->dst_address['line0'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[0]);
|
||||
$this->dst_address['line1'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[1]);
|
||||
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[2]);
|
||||
$this->dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), $address_lines[3]);
|
||||
}
|
||||
|
||||
$this->dst_address['countryCode'] = $so_data['cecountry'];
|
||||
|
||||
if(strtolower($so_data['cecountry']) == 'sl') {
|
||||
$this->dst_address['zipCode'] = (string) str_ireplace(array('SI-', 'SL-'), '', mb_substr($so_data['przipcode'], 0, 5));
|
||||
} else {
|
||||
$this->dst_address['zipCode'] = (string) mb_substr($so_data['przipcode'], 0, 5);
|
||||
}
|
||||
$this->dst_address['city'] = (string) mb_substr($so_data['prtown'], 0, 35);
|
||||
$this->dst_address['mobileNumber'] = (string) mb_substr($so_data['cephonenumber'], 0, 32);
|
||||
if(strlen($this->dst_address['mobileNumber']) > 10) {
|
||||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
|
||||
$this->dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(mb_substr($this->dst_address['mobileNumber'], 0, 2) != '06' && mb_substr($this->dst_address['mobileNumber'], 0, 2) != '07') {
|
||||
$this->dst_address['mobileNumber'] = '0600000000';
|
||||
}
|
||||
|
||||
if(($doorcode = (string) mb_substr($so_data['cedoorcode1'], 0, 8)) != '') {
|
||||
$this->dst_address['doorCode1'] = (string) mb_substr($so_data['cedoorcode1'], 0, 8);
|
||||
}
|
||||
if(($doorcode = (string) mb_substr($so_data['cedoorcode2'], 8, 8)) != '') {
|
||||
$this->dst_address['doorCode2'] = (string) mb_substr($so_data['cedoorcode1'], 8, 8);
|
||||
}
|
||||
|
||||
$this->instructions = trim(str_replace(array('°', '|', ' ', '', "\n", "\r"), ' ', (string) $so_data['cedeliveryinformation']));
|
||||
$this->prid = $so_data['prid'];
|
||||
} else {
|
||||
$this->dst_address['companyName'] = (string) mb_substr(str_replace(array('', $unicode_ack, $unicode_ack2), ' ', $dst_address->company), 0, 35);
|
||||
$this->dst_address['lastName'] = (string) mb_substr(str_replace(array('', $unicode_ack, $unicode_ack2), ' ', $dst_address->firstname), 0, 35);
|
||||
$this->dst_address['firstName'] = (string) mb_substr(strtoupper(str_replace(array('', $unicode_ack, $unicode_ack2), ' ', $dst_address->lastname)), 0, 29);
|
||||
$this->dst_address['email'] = (string) $dst_customer->email;
|
||||
if($dst_address->id_country == 193) {
|
||||
$this->dst_address['zipCode'] = mb_substr((string) str_ireplace(array('SI-', 'SL-'), '', $dst_address->postcode), 0, 5);
|
||||
} else {
|
||||
$this->dst_address['zipCode'] = mb_substr((string) str_replace(array(' ', '-'), '', $dst_address->postcode), 0, 5);
|
||||
}
|
||||
$this->dst_address['city'] = (string) mb_substr(strtoupper($dst_address->city), 0, 35);
|
||||
if(in_array($dst_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
|
||||
$this->dst_address['countryCode'] = 'FR';
|
||||
} else {
|
||||
$this->dst_address['countryCode'] = (string) $dst_country->iso_code;
|
||||
}
|
||||
$this->dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address1);
|
||||
$this->dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address2);
|
||||
$this->instructions = trim(str_replace(array('°', '|', ' ', '', "\n", "\r"), ' ', (string) $dst_address->other));
|
||||
|
||||
if(in_array($dst_country->iso_code, array('FR', 'AD', 'MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
|
||||
if($dst_address->phone != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone)) {
|
||||
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
|
||||
} elseif($dst_address->phone_mobile != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone_mobile)) {
|
||||
$this->dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
|
||||
}
|
||||
|
||||
if(strlen($this->dst_address['phoneNumber']) > 10) {
|
||||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['phoneNumber'])) {
|
||||
$this->dst_address['phoneNumber'] = '0'.mb_substr(mb_substr($this->dst_address['phoneNumber'], -10), 1);
|
||||
}
|
||||
}
|
||||
if(strlen($this->dst_address['mobileNumber']) > 10) {
|
||||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $this->dst_address['mobileNumber'])) {
|
||||
$this->dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($this->dst_address['mobileNumber'], -10), 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if($dst_country->iso_code == 'BE') {
|
||||
if($dst_address->phone != '') {
|
||||
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
|
||||
} else {
|
||||
$this->dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
|
||||
}
|
||||
$this->dst_address['mobileNumber'] = '';
|
||||
} else {
|
||||
if($dst_address->phone != '') {
|
||||
$this->dst_address['phoneNumber'] = (string) $dst_address->phone;
|
||||
}
|
||||
if($dst_address->phone_mobile != '') {
|
||||
$this->dst_address['mobileNumber'] = (string) $dst_address->phone_mobile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($dst_country->iso_code == 'FR') {
|
||||
$this->product_type = 'COLD';
|
||||
} else {
|
||||
$this->product_type = 'COLI';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function array_to_xml($array, $xml)
|
||||
{
|
||||
foreach($array as $key => $value) {
|
||||
if(is_array($value)) {
|
||||
if(!is_numeric($key)){
|
||||
$subnode = $xml->addChild("$key");
|
||||
$this->array_to_xml($value, $subnode);
|
||||
}
|
||||
else{
|
||||
$subnode = $xml->addChild("item$key");
|
||||
$this->array_to_xml($value, $subnode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$xml->addChild("$key",htmlspecialchars("$value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function xml_to_array($xml, $array=array())
|
||||
{
|
||||
foreach((array) $xml as $index => $node) {
|
||||
$array[$index] = (is_object($node))? $this->xml_to_array($node): $node;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function setWeight($weight=0)
|
||||
{
|
||||
$this->weight = rtrim((string) $weight, '0');
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
if(Validate::isLoadedObject($this->order)) {
|
||||
global $cookie;
|
||||
|
||||
$carrier_config = array(
|
||||
'api' => array(
|
||||
'wsu' => array(
|
||||
'contract' => (int) Configuration::get('LAPOSTEWS_API_CONTRACT_WSU');,
|
||||
'password' => Configuration::get('LAPOSTEWS_API_PASSWORD_WSU');,
|
||||
)
|
||||
),
|
||||
'exp_commercial_name' => Configuration::get('LAPOSTEWS_COMMERCIALNAME'),
|
||||
'exp_firstname' => Configuration::get('LAPOSTEWS_EXP_FIRSTNAME'),
|
||||
'exp_lastname' => Configuration::get('LAPOSTEWS_EXP_LASTNAME'),
|
||||
'exp_company' => Configuration::get('LAPOSTEWS_EXP_COMPANY'),
|
||||
'exp_address1' => Configuration::get('LAPOSTEWS_EXP_ADDR1'),
|
||||
'exp_address2' => Configuration::get('LAPOSTEWS_EXP_ADDR2'),
|
||||
'exp_city' => Configuration::get('LAPOSTEWS_EXP_CITY'),
|
||||
'exp_postcode' => Configuration::get('LAPOSTEWS_EXP_POSTALCODE'),
|
||||
'exp_email' => Configuration::get('LAPOSTEWS_EXP_EMAIL'),
|
||||
'exp_country' => Configuration::get('LAPOSTEWS_EXP_COUNTRY'),
|
||||
'exp_phone' => Configuration::get('LAPOSTEWS_EXP_PHONE'),
|
||||
);
|
||||
|
||||
$c = new SoapClient(
|
||||
'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl',
|
||||
array(
|
||||
'trace' => 0,
|
||||
'exceptions' => 1,
|
||||
'cache_wsdl' => 0? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE,
|
||||
)
|
||||
);
|
||||
try {
|
||||
$exp_country = new Country((int) $carrier_config['exp_country']);
|
||||
if(in_array($exp_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
|
||||
$countryCode = 'FR';
|
||||
} else {
|
||||
$countryCode = (string) $exp_country->iso_code;
|
||||
}
|
||||
$phone = $carrier_config['exp_phone'];
|
||||
if(strlen($phone) > 10) {
|
||||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $phone)) {
|
||||
$phone = '0'.mb_substr(mb_substr($phone, -10), 1);
|
||||
}
|
||||
}
|
||||
$soap = new SimpleXMLElement('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" />');
|
||||
$soap->addChild('soapenv:Header');
|
||||
$children = $soap->addChild('soapenv:Body');
|
||||
$children = $children->addChild('sls:generateLabel', NULL, 'http://sls.ws.coliposte.fr');
|
||||
$children = $children->addChild('generateLabelRequest', NULL, '');
|
||||
$this->array_to_xml(array(
|
||||
'contractNumber' => $carrier_config['api']['wsu']['contract'],
|
||||
'password' => $carrier_config['api']['wsu']['password'],
|
||||
'outputFormat' => array(
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
'outputPrintingType' => 'DPL_10x15_203dpi', // DPL_10x15_300dpi / PDF_10x15_300dpi / PDF_A4_300dpi
|
||||
),
|
||||
'letter' => array(
|
||||
'service' => array(
|
||||
/*
|
||||
COLD = Colissimo Access FR
|
||||
COL = Colissimo Expert FR
|
||||
COM = Colissimo Access FR
|
||||
CDS = Colissimo Expert OM
|
||||
COLI = Colissimo Expert Inter
|
||||
DOM = SoCol Dom SS
|
||||
DOS = SoCol Dom AS
|
||||
BPR = Socol Bureau de poste FR
|
||||
A2P = Socol Commerçant FR
|
||||
CMT = Socol commercant FR
|
||||
BDP = Socol Bureau de poste inter
|
||||
*/
|
||||
'productCode' => $this->product_type,
|
||||
'depositDate' => date('Y-m-d'),
|
||||
'transportationAmount' => (int) ($this->order->total_shipping * 100),
|
||||
'orderNumber' => (string) $this->order->id,
|
||||
'commercialName' => $carrier_config['exp_commercial_name'],
|
||||
'returnTypeChoice' => 3, // 2 = return, 3 = do not return
|
||||
),
|
||||
'parcel' => array(
|
||||
'weight' => 0.24,
|
||||
'instructions' => $this->instructions,
|
||||
'pickupLocationId' => $this->prid,
|
||||
),
|
||||
'customsDeclarations' => array(
|
||||
),
|
||||
'sender' => array(
|
||||
'senderParcelRef' => 'REF'.$this->order->id,
|
||||
'address' => array(
|
||||
'companyName' => (string) mb_substr($carrier_config['exp_company'], 0, 35),
|
||||
'line2' => (string) mb_substr(strtoupper($carrier_config['exp_address1']), 0, 35),
|
||||
'line3' => (string) mb_substr(strtoupper($carrier_config['exp_address2']), 0, 35),
|
||||
'countryCode' => $countryCode,
|
||||
'city' => (string) mb_substr(strtoupper($carrier_config['exp_city']), 0, 35),
|
||||
'zipCode' => (string) mb_substr($carrier_config['exp_postcode'], 0, 5),
|
||||
'phoneNumber' => $phone,
|
||||
'email' => mb_substr((string) $carrier_config['exp_email'], 0, 80),
|
||||
'language' => 'FR',
|
||||
),
|
||||
),
|
||||
'addressee' => array(
|
||||
'address' => $this->dst_address,
|
||||
),
|
||||
),
|
||||
), $children);
|
||||
$response = new SoapResponse($c->__doRequest($soap->asXML(), 'https://ws.colissimo.fr/sls-ws/SlsServiceWS', 'generateLabel', '2.0', 0));
|
||||
return array(
|
||||
'data' => new SimpleXMLElement(
|
||||
'<?xml version=\'1.0\' standalone=\'yes\'?>'.str_replace(
|
||||
array(
|
||||
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:generateLabelResponse xmlns:ns2="http://sls.ws.coliposte.fr">',
|
||||
'</ns2:generateLabelResponse></soap:Body></soap:Envelope>',
|
||||
),
|
||||
'',
|
||||
$response->soapResponse['data']
|
||||
)
|
||||
),
|
||||
'label' => $response->attachments[0]['data'],
|
||||
);
|
||||
} catch(Exception $e) {
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user