567 lines
21 KiB
PHP
567 lines
21 KiB
PHP
<?php
|
||
if(!defined('_PS_VERSION_')) {
|
||
exit;
|
||
}
|
||
|
||
|
||
class WS_ServiceCallContextVO {
|
||
public $dateDeposite; // dateTime
|
||
//~ public $dateValidation; // dateTime
|
||
public $returnType = 'CreatePDFFile'; // RequestTypeVO, CreatePDFFile / ReturnPDFInResponse
|
||
public $serviceType; // string
|
||
public $crbt = FALSE; // bool
|
||
public $removalBAL = FALSE; // bool
|
||
//~ public VATCode; // int
|
||
//~ public VATPercentage; // int
|
||
//~ public VATAmount; // int
|
||
//~ public transportationAmount; // int
|
||
//~ public totalAmount; // int, oblig pour Andorre
|
||
//public $portPaye = FALSE; // bool
|
||
//~ public FTD; // bool
|
||
//~ public FTDAmount; // int
|
||
//~ public returnOption; // bool
|
||
//~ public returnOptionAmount; // int
|
||
|
||
public function __construct() {
|
||
$this->serviceType = (Module::isInstalled('socolissimo')? 'SO': 'DOM');
|
||
$this->dateDeposite = date('Y-m-d\TH:i:s.000P');
|
||
}
|
||
}
|
||
|
||
|
||
class WS_ExpEnvVO {
|
||
public $alert = 'none'; // AlertTypeVO
|
||
public $addressVO; // AddressVO
|
||
}
|
||
|
||
|
||
class WS_AddressVO {
|
||
//~ public $companyName; // string
|
||
//~ public $Civility; // string
|
||
//~ public $Name; // string
|
||
//~ public $Surname; // string
|
||
//~ public $line0; // string
|
||
//~ public $line1; // string
|
||
public $line2 = ''; // string
|
||
//~ public $line3; // string
|
||
//~ public $phone; // string, not required for DOM or DOS only
|
||
//~ public $MobileNumber; // string
|
||
//~ public $DoorCode1; // string
|
||
//~ public $DoorCode2; // string
|
||
//~ public $Interphone; // string
|
||
//~ public $country; // string
|
||
public $countryCode; // string
|
||
public $city; // string
|
||
public $email; // string
|
||
public $postalCode; // string
|
||
}
|
||
|
||
|
||
class WS_DestEnvVO {
|
||
public $ref = '';
|
||
public $alert = 'none'; // AlertTypeVO
|
||
public $addressVO; // AddressVO
|
||
public $codeBarForreference = FALSE; // bool
|
||
public $deliveryError = FALSE; // bool
|
||
}
|
||
|
||
|
||
class WS_ServiceCallContextV2 extends WS_ServiceCallContextVO {
|
||
//~ public $commandNumber; // string
|
||
public $commercialName; // string
|
||
|
||
public function __construct() {
|
||
parent::__construct();
|
||
|
||
$this->commercialName = Configuration::get('LAPOSTEWS_COMMERCIALNAME', 'ONLINE SHOP');
|
||
}
|
||
}
|
||
|
||
|
||
class WS_Letter {
|
||
public $password; // string, not null
|
||
public $contractNumber; // int, not null
|
||
public $profil = 'SPECIFIQUE'; // string
|
||
public $service; // ServiceCallContextV2
|
||
public $parcel; // ParcelVO
|
||
public $dest; // DestEnvVO
|
||
public $exp; // ExpEnvVO
|
||
|
||
public function __construct() {
|
||
$this->contractNumber = (int) Configuration::get('LAPOSTEWS_API_CONTRACT');
|
||
$this->password = Configuration::get('LAPOSTEWS_API_PASSWORD');
|
||
}
|
||
}
|
||
|
||
|
||
class WS_GetLetterColissimoRequest {
|
||
public $letter; // Letter
|
||
|
||
public function __construct($letter=NULL) {
|
||
$this->letter = $letter;
|
||
}
|
||
}
|
||
|
||
class WS_Contents {
|
||
public $article = array(); // ArticleVO, 1..10
|
||
public $categorie = 3; // CategorieVO
|
||
}
|
||
|
||
class WS_ArticleVO {
|
||
public $description;
|
||
public $quantite;
|
||
public $poids;
|
||
public $valeur;
|
||
public $numTarifaire;
|
||
public $paysOrigine = 'FR';
|
||
}
|
||
|
||
class WS_ParcelVO {
|
||
public $insuranceRange = '00'; // string, not null
|
||
public $typeGamme; // string, not null
|
||
//~ public $parcelNumber; // string, not null
|
||
//~ public $returnTypeChoice; // int, not null
|
||
//~ public $insuranceValue; // int, not null
|
||
//~ public $recommendationLevel; // string, not null
|
||
//~ public $RecommendationAmount; // int
|
||
public $weight = 0.01; // float, not null, /!\ décimales si > 0 uniquement
|
||
public $horsGabarit = FALSE;
|
||
//~ public $HorsGabaritAmount; // int
|
||
public $DeliveryMode = 'DOM'; // DeliveryModeVO: DOM, RDV, BPR, ACP, CDI, A2P, MRL, CIT, DOS
|
||
//public $ReturnReceipt = FALSE; // bool
|
||
//public $Recommendation = FALSE; // bool
|
||
//~ public $Instructions; // string
|
||
//public $RegateCode = ''; // string, vide si domicile, sinon point de livraison
|
||
public $contents; // ContentsVO, not null, required if Andorre
|
||
}
|
||
|
||
|
||
class Parcel {
|
||
public $mode;
|
||
|
||
public $parcelVO;
|
||
public $getLetterColissimoRequest;
|
||
public $letter;
|
||
public $serviceCallContextV2;
|
||
|
||
public $order;
|
||
|
||
public function __construct() {
|
||
$this->mode = (int) Configuration::get('LAPOSTEWS_MODE'); // 0: test, 1: production
|
||
|
||
$this->serviceCallContextV2 = new WS_ServiceCallContextV2();
|
||
|
||
$this->parcelVO = new WS_ParcelVO();
|
||
|
||
$this->letter = new WS_Letter();
|
||
$this->letter->parcel = $this->parcelVO;
|
||
$this->letter->service = $this->serviceCallContextV2;
|
||
|
||
$this->letter->dest = new WS_DestEnvVO();
|
||
$this->letter->exp = new WS_ExpEnvVO();
|
||
|
||
$this->letter->contents = new WS_Contents();
|
||
}
|
||
|
||
public function addArticle($description, $qty, $weight, $value, $wco_nom) {
|
||
if(count($this->letter->contents->article) < 10) {
|
||
$article = new WS_ArticleVO();
|
||
if(mb_strlen($description) > 61) {
|
||
$article->description = mb_substr($customs_details[$k]['product_name'], 0, 61).'...';
|
||
} else {
|
||
$article->description = $description;
|
||
}
|
||
$article->quantite = (int) $qty;
|
||
$article->poids = str_replace('.00', '', (string) sprintf('%.02f', (float) $weight));
|
||
$article->valeur = str_replace('.00', '', (string) sprintf('%.02f', (float) $value));
|
||
$article->numTarifaire = $wco_nom;
|
||
$this->letter->contents->article[] = $article;
|
||
}
|
||
}
|
||
|
||
public function getShippingNumber($gamme) {
|
||
if($gamme == 'SO+A2P') {
|
||
$prefix = Configuration::get('LAPOSTEWS_RANGE_0_P');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
|
||
Db::getInstance()->Execute('START TRANSACTION');
|
||
$res = Db::getInstance()->ExecuteS('
|
||
SELECT `value`
|
||
FROM `'._DB_PREFIX_.'logistics_shipping`
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "0"
|
||
FOR UPDATE
|
||
');
|
||
|
||
$max = (int) $res[0]['value'] + 1;
|
||
|
||
Db::getInstance()->ExecuteS('
|
||
UPDATE `'._DB_PREFIX_.'logistics_shipping`
|
||
SET `value` = "'.(int) $max.'"
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "0"
|
||
');
|
||
|
||
Db::getInstance()->Execute('COMMIT');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
|
||
} elseif($gamme == 'SO+BPR') {
|
||
$prefix = Configuration::get('LAPOSTEWS_RANGE_1_P');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
|
||
Db::getInstance()->Execute('START TRANSACTION');
|
||
$res = Db::getInstance()->ExecuteS('
|
||
SELECT `value`
|
||
FROM `'._DB_PREFIX_.'logistics_shipping`
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "1"
|
||
FOR UPDATE
|
||
');
|
||
|
||
$max = (int) $res[0]['value'] + 1;
|
||
|
||
Db::getInstance()->ExecuteS('
|
||
UPDATE `'._DB_PREFIX_.'logistics_shipping`
|
||
SET `value` = "'.(int) $max.'"
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "1"
|
||
');
|
||
|
||
Db::getInstance()->Execute('COMMIT');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
|
||
} elseif($gamme == 'SO+DOS') {
|
||
$prefix = Configuration::get('LAPOSTEWS_RANGE_2_P');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
|
||
Db::getInstance()->Execute('START TRANSACTION');
|
||
$res = Db::getInstance()->ExecuteS('
|
||
SELECT `value`
|
||
FROM `'._DB_PREFIX_.'logistics_shipping`
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "2"
|
||
FOR UPDATE
|
||
');
|
||
|
||
$max = (int) $res[0]['value'] + 1;
|
||
|
||
Db::getInstance()->ExecuteS('
|
||
UPDATE `'._DB_PREFIX_.'logistics_shipping`
|
||
SET `value` = "'.(int) $max.'"
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "2"
|
||
');
|
||
|
||
Db::getInstance()->Execute('COMMIT');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
|
||
} elseif($gamme == 'SO+DOM') {
|
||
$prefix = Configuration::get('LAPOSTEWS_RANGE_3_P');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
|
||
Db::getInstance()->Execute('START TRANSACTION');
|
||
$res = Db::getInstance()->ExecuteS('
|
||
SELECT `value`
|
||
FROM `'._DB_PREFIX_.'logistics_shipping`
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "3"
|
||
FOR UPDATE
|
||
');
|
||
|
||
$max = (int) $res[0]['value'] + 1;
|
||
|
||
Db::getInstance()->ExecuteS('
|
||
UPDATE `'._DB_PREFIX_.'logistics_shipping`
|
||
SET `value` = "'.(int) $max.'"
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "3"
|
||
');
|
||
|
||
Db::getInstance()->Execute('COMMIT');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
|
||
} else {
|
||
$prefix = Configuration::get('LAPOSTEWS_RANGE_4_P');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 0');
|
||
Db::getInstance()->Execute('START TRANSACTION');
|
||
$res = Db::getInstance()->ExecuteS('
|
||
SELECT `value`
|
||
FROM `'._DB_PREFIX_.'logistics_shipping`
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "4"
|
||
FOR UPDATE
|
||
');
|
||
|
||
$max = (int) $res[0]['value'] + 1;
|
||
|
||
Db::getInstance()->ExecuteS('
|
||
UPDATE `'._DB_PREFIX_.'logistics_shipping`
|
||
SET `value` = "'.(int) $max.'"
|
||
WHERE `carrier` = "laposte"
|
||
AND `delivery_mode` = "4"
|
||
');
|
||
|
||
Db::getInstance()->Execute('COMMIT');
|
||
Db::getInstance()->Execute('SET AUTOCOMMIT = 1');
|
||
}
|
||
|
||
$max = sprintf('%08d', $max);
|
||
|
||
$key = ((int) substr($max, 0, 1) * 8 + (int) substr($max, 1, 1) * 6 + (int) substr($max, 2, 1) * 4 + (int) substr($max, 3, 1) * 2 + (int) substr($max, 4, 1) * 3 + (int) substr($max, 5, 1) * 5 + (int) substr($max, 6, 1) * 9 + (int) substr($max, 7, 1) * 7) % 11;
|
||
|
||
if($key == 0) {
|
||
$key = 5;
|
||
} elseif($key == 1) {
|
||
$key = 0;
|
||
} else {
|
||
$key = 11 - $key;
|
||
}
|
||
|
||
return $prefix.$max.$key.'FR';
|
||
}
|
||
|
||
public function attachOrder($id_order) {
|
||
global $cookie;
|
||
|
||
$this->order = new Order($id_order);
|
||
|
||
if(Validate::isLoadedObject($this->order)) {
|
||
$this->serviceCallContextV2->commandNumber = $this->order->id;
|
||
|
||
$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);
|
||
|
||
$dst_address_ws = new WS_AddressVO();
|
||
|
||
if($dst_address->company != '') {
|
||
$dst_address_ws->companyName = mb_substr($dst_address->company, 0, 32);
|
||
}
|
||
$dst_address_ws->Name = (string) mb_substr(str_replace(array('’', 'ª', 'ł', 'ň', 'ć', 'ņ', 'č',), array('\'', 'a', 'l', 'n', 'c', 'n', 'c',), $dst_address->firstname), 0, 32);
|
||
$dst_address_ws->Surname = (string) mb_substr(strtoupper(str_replace(array('ª', 'ł', 'ň', 'ć', 'ņ', 'č',), array('a', 'l', 'n', 'c', 'n', 'c',), $dst_address->lastname)), 0, 32);
|
||
$dst_address_ws->email = (string) $dst_customer->email;
|
||
if($dst_address->id_country == 193) {
|
||
$dst_address_ws->postalCode = str_replace('SI', '', (string) str_replace(array(' ', '-'), '', $dst_address->postcode));
|
||
} elseif($dst_address->id_country == 125) {
|
||
$dst_address_ws->postalCode = str_replace('LV', '', (string) str_replace(array(' ', '-'), '', $dst_address->postcode));
|
||
} else {
|
||
$dst_address_ws->postalCode = (string) str_replace(array(' ', '-'), '', $dst_address->postcode);
|
||
}
|
||
$dst_address_ws->city = (string) mb_substr(strtoupper($dst_address->city), 0, 32);
|
||
|
||
if(in_array($dst_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
|
||
$dst_address_ws->countryCode = 'FR';
|
||
} else {
|
||
$dst_address_ws->countryCode = (string) $dst_country->iso_code;
|
||
}
|
||
$dst_address_ws->country = (string) mb_substr($dst_country->name[$cookie->id_lang], 0, 32);
|
||
|
||
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.'
|
||
'))
|
||
&& ($so_data['cecountry'] == 'FR' || $so_data['cecountry'] == 'AD' || $so_data['cecountry'] == 'MO')
|
||
) {
|
||
$this->parcelVO->typeGamme = 'SO';
|
||
|
||
$unicode_0 = json_decode('"\u0006"');
|
||
$unicode_1 = json_decode('"\u200b"');
|
||
$unicode_2 = json_decode('"\u00ad"');
|
||
|
||
$dst_address_ws->email = $so_data['ceemail'];
|
||
$dst_address_ws->Name = mb_substr(str_replace('ł', 'l', $so_data['cename']), 0, 32);
|
||
$dst_address_ws->Surname = mb_substr(str_replace('ł', 'l', $so_data['cefirstname']), 0, 32);
|
||
|
||
$address_lines = array();
|
||
for($i = 1; $i < 5; $i++) {
|
||
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
|
||
$address_lines[] = str_replace(
|
||
array('Á', '°', 'º', 'º', 'º', 'ª', "\t", "\n", "\r", ' ', '–', '', $unicode_0, $unicode_1, $unicode_2,),
|
||
array('A', '', '', '', '', 'a', ' ', ' ', ' ', ' ', '-', '', '', '', '',),
|
||
trim($line)
|
||
);
|
||
}
|
||
}
|
||
|
||
if(count($address_lines) == 1) {
|
||
$dst_address_ws->line2 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
|
||
} elseif(count($address_lines) == 2) {
|
||
$dst_address_ws->line2 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
|
||
$dst_address_ws->line3 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
|
||
} elseif(count($address_lines) == 3) {
|
||
$dst_address_ws->line0 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
|
||
$dst_address_ws->line2 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
|
||
$dst_address_ws->line3 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[2]);
|
||
} else {
|
||
$dst_address_ws->line0 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[0]);
|
||
$dst_address_ws->line1 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[1]);
|
||
$dst_address_ws->line2 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[2]);
|
||
$dst_address_ws->line3 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā',), array('\'', ' ', '', '', '', 'a', 'a'), $address_lines[3]);
|
||
}
|
||
|
||
$dst_address_ws->postalCode = (string) mb_substr($so_data['przipcode'], 0, 32);
|
||
$dst_address_ws->city = (string) mb_substr($so_data['prtown'], 0, 32);
|
||
$dst_address_ws->MobileNumber = (string) mb_substr($so_data['cephonenumber'], 0, 32);
|
||
if(strlen($dst_address_ws->MobileNumber) > 10) {
|
||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->MobileNumber)) {
|
||
$dst_address_ws->MobileNumber = '0'.mb_substr(mb_substr($dst_address_ws->MobileNumber, -10), 1);
|
||
}
|
||
}
|
||
|
||
if(mb_substr($dst_address_ws->MobileNumber, 0, 2) != '06' && mb_substr($dst_address_ws->MobileNumber, 0, 2) != '07') {
|
||
$dst_address_ws->MobileNumber = '0600000000';
|
||
}
|
||
|
||
if(($doorcode = (string) mb_substr($so_data['cedoorcode1'], 0, 32)) != '') {
|
||
$dst_address_ws->DoorCode1 = $doorcode;
|
||
}
|
||
if(($doorcode = (string) mb_substr($so_data['cedoorcode2'], 0, 32)) != '') {
|
||
$dst_address_ws->DoorCode2 = $doorcode;
|
||
}
|
||
|
||
$this->letter->parcel->Instructions = trim(str_replace(array('°', '|', ' ', '', "\n", "\r"), ' ', (string) $so_data['cedeliveryinformation']));
|
||
$this->letter->parcel->DeliveryMode = (string) $so_data['delivery_mode'];
|
||
if(!in_array($this->letter->parcel->DeliveryMode, array('DOM', 'DOS', 'RDV'))) {
|
||
$this->letter->parcel->RegateCode = $so_data['prid']; //(string) ltrim($so_data['prid'], '0');
|
||
error_log($this->letter->parcel->RegateCode);
|
||
}
|
||
} else {
|
||
//$this->serviceCallContextV2->serviceType = 'DOM';
|
||
if($dst_country->iso_code == 'FR' /*|| $dst_country->iso_code == 'BE'*/) {
|
||
$this->parcelVO->typeGamme = 'SO';
|
||
} else {
|
||
$this->parcelVO->typeGamme = 'EI';
|
||
}
|
||
|
||
if($dst_country->iso_code != 'FR') {
|
||
$this->parcelVO->parcelNumber = $this->getShippingNumber($this->parcelVO->typeGamme.'+'.$this->parcelVO->DeliveryMode);
|
||
$this->parcelVO->returnTypeChoice = 3;
|
||
}
|
||
|
||
$dst_address_ws->line2 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā', 'ė'), array('\'', ' ', '', '', '', 'a', 'a', 'e'), (string) $dst_address->address1);
|
||
$dst_address_ws->line3 = str_replace(array('’', '°', 'º', 'º', 'º', 'ª', 'ā', 'ė'), array('\'', ' ', '', '', '', 'a', 'a', 'e'), (string) $dst_address->address2);
|
||
|
||
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)) {
|
||
$dst_address_ws->phone = (string) $dst_address->phone;
|
||
} elseif($dst_address->phone_mobile != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone_mobile)) {
|
||
$dst_address_ws->phone = (string) $dst_address->phone_mobile;
|
||
}
|
||
|
||
if(strlen($dst_address_ws->phone) > 10) {
|
||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->phone)) {
|
||
$dst_address_ws->phone = '0'.mb_substr(mb_substr($dst_address_ws->phone, -10), 1);
|
||
}
|
||
}
|
||
if(strlen($dst_address_ws->phone_mobile) > 10) {
|
||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address_ws->phone_mobile)) {
|
||
$dst_address_ws->phone_mobile = '0'.mb_substr(mb_substr($dst_address_ws->phone_mobile, -10), 1);
|
||
}
|
||
}
|
||
} else {
|
||
/*$this->parcelVO->typeGamme = 'AI';
|
||
$this->letter->parcel->DeliveryMode = 'DOM';*/
|
||
|
||
if($dst_country->iso_code == 'BE') {
|
||
if($dst_address->phone != '') {
|
||
$dst_address_ws->phone = (string) $dst_address->phone;
|
||
} else {
|
||
$dst_address_ws->phone = (string) $dst_address->phone_mobile;
|
||
}
|
||
$dst_address_ws->MobileNumber = '';
|
||
} else {
|
||
if($dst_address->phone != '') {
|
||
$dst_address_ws->phone = (string) $dst_address->phone;
|
||
}
|
||
if($dst_address->phone_mobile != '') {
|
||
$dst_address_ws->MobileNumber = (string) $dst_address->phone_mobile;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$this->letter->dest->addressVO = $dst_address_ws;
|
||
$this->letter->dest->ref = $this->order->id;
|
||
|
||
$exp_country = new Country((int) Configuration::get('LAPOSTEWS_EXP_COUNTRY'));
|
||
$exp_address_ws = new WS_AddressVO();
|
||
$exp_address_ws->companyName = (string) mb_substr(Configuration::get('LAPOSTEWS_EXP_COMPANY', ''), 0, 32);
|
||
$exp_address_ws->Name = (string) mb_substr(Configuration::get('LAPOSTEWS_EXP_FIRSTNAME', ''), 0, 32);
|
||
$exp_address_ws->Surname = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_LASTNAME', '')), 0, 32);
|
||
$exp_address_ws->email = (string) Configuration::get('LAPOSTEWS_EXP_EMAIL', '');
|
||
$exp_address_ws->postalCode = (string) Configuration::get('LAPOSTEWS_EXP_POSTALCODE', '');
|
||
$exp_address_ws->city = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_CITY', '')), 0, 32);
|
||
$exp_address_ws->line2 = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_ADDR1', '')), 0, 32);
|
||
$exp_address_ws->line3 = (string) mb_substr(strtoupper(Configuration::get('LAPOSTEWS_EXP_ADDR2', '')), 0, 32);
|
||
if(in_array($exp_country->iso_code, array('MO', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
|
||
$exp_address_ws->countryCode = 'FR';
|
||
} else {
|
||
$exp_address_ws->countryCode = (string) $exp_country->iso_code;
|
||
}
|
||
$exp_address_ws->country = (string) mb_substr($exp_country->name[$cookie->id_lang], 0, 32);
|
||
$exp_address_ws->phone = (string) Configuration::get('LAPOSTEWS_EXP_PHONE', '');
|
||
|
||
if(strlen($exp_address_ws->phone) > 10) {
|
||
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $exp_address_ws->phone)) {
|
||
$exp_address_ws->phone = '0'.mb_substr(mb_substr($exp_address_ws->phone, -10), 1);
|
||
}
|
||
}
|
||
|
||
$this->letter->exp->addressVO = $exp_address_ws;
|
||
}
|
||
}
|
||
|
||
public function setWeight($weight=0) {
|
||
$this->parcelVO->weight = rtrim((string) $weight, '0');
|
||
}
|
||
|
||
public function send() {
|
||
if(Validate::isLoadedObject($this->order)) {
|
||
global $cookie;
|
||
|
||
$c = new SoapClient(
|
||
'http://ws.colissimo.fr/soap.shippingclpV2/services/WSColiPosteLetterService?wsdl',
|
||
array(
|
||
'trace' => $this->mode,
|
||
'exceptions' => !$this->mode,
|
||
'cache_wsdl' => $this->mode? WSDL_CACHE_MEMORY: WSDL_CACHE_NONE,
|
||
)
|
||
);
|
||
|
||
$this->getLetterColissimoRequest = new WS_GetLetterColissimoRequest($this->letter);
|
||
|
||
try {
|
||
/*if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
|
||
$x = $c->getLetterColissimo($this->getLetterColissimoRequest);
|
||
|
||
if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
|
||
mail('perron@antadis.com', 'PSS TEST PANZOU', serialize($c->__getLastRequest())."\n".serialize($c->__getLastResponse())."\n".serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
|
||
}
|
||
|
||
return $x;
|
||
}*/
|
||
|
||
if($this->letter->dest->addressVO->countryCode == 'FR') {
|
||
// $x = $c->getLetterColissimo(array('in0' => $this->letter));
|
||
$x = $c->getLetterColissimo($this->getLetterColissimoRequest);
|
||
|
||
/*if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
|
||
mail('perron@antadis.com', 'PSS TEST PANZOU', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
|
||
}*/
|
||
} else {
|
||
//if($_SERVER['REMOTE_ADDR'] == '78.226.56.137') {
|
||
$this->getLetterColissimoRequest->letter->contractNumber = (int) Configuration::get('LAPOSTEWS_API_CONTRACT2');
|
||
$this->getLetterColissimoRequest->letter->password = Configuration::get('LAPOSTEWS_API_PASSWORD2');
|
||
$x = $c->genererEtiquetteBIC3($this->getLetterColissimoRequest);
|
||
//}
|
||
//var_dump($this->getLetterColissimoRequest);
|
||
//var_dump($x);
|
||
mail('perron@antadis.com', 'BBB TEST LOG', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest));
|
||
}
|
||
|
||
return $x;
|
||
} catch(Exception $e) {
|
||
mail('perron@antadis.com', 'BBB TEST LOG', serialize($x)."\r\n\r\n".serialize($this->getLetterColissimoRequest)."\n".serialize($e));
|
||
return $e;
|
||
}
|
||
} else {
|
||
return FALSE;
|
||
}
|
||
}
|
||
}
|