// Merge -> 10309

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10333 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-11-21 11:05:10 +00:00
parent 2537c72189
commit 9d10de0848
365 changed files with 11185 additions and 1571 deletions
@@ -0,0 +1,68 @@
<?php
class OrderInfoTnt
{
private $_idOrder;
public function __construct($id_order)
{
$this->_idOrder = $id_order;
}
public function getInfo()
{
$info = Db::getInstance()->ExecuteS('SELECT o.shipping_number, a.lastname, a.firstname, a.address1, a.address2, a.postcode, a.city, a.phone, c.email, c.id_customer, a.company
FROM `'._DB_PREFIX_.'orders` as o, `'._DB_PREFIX_.'address` as a, `'._DB_PREFIX_.'customer` as c
WHERE o.id_order = "'.$this->_idOrder.'" AND a.id_address = o.id_address_delivery AND c.id_customer = o.id_customer');
if (!$info)
return false;
$weight = Db::getInstance()->ExecuteS('SELECT p.weight, o.product_quantity
FROM `'._DB_PREFIX_.'order_detail` as o, `'._DB_PREFIX_.'product` as p
WHERE o.id_order = "'.$this->_idOrder.'" AND p.id_product = o.product_id');
$option = Db::getInstance()->ExecuteS('SELECT t.option
FROM `'._DB_PREFIX_.'tnt_carrier_option` as t , `'._DB_PREFIX_.'orders` as o
WHERE t.id_carrier = o.id_carrier AND o.id_order = "'.$this->_idOrder.'"');
if ($option != null && strpos($option[0]['option'], "D") !== false)
$dropOff = Db::getInstance()->ExecuteS('SELECT d.code, d.name, d.address, d.zipcode, d.city
FROM `'._DB_PREFIX_.'tnt_carrier_drop_off` as d , `'._DB_PREFIX_.'orders` as o
WHERE d.id_cart = o.id_cart AND o.id_order = "'.$this->_idOrder.'"');
$w = 0;
$tooBig = false;
foreach ($weight as $key => $val)
{
while ($val['product_quantity'] > 0)
{
if ((int)($val['weight']) > 20)
return "Un ou plusieurs articles sont sup&eacute;rieurs &agrave; 20 Kg<br/>Vous devez contacter votre commercial TNT";
if ($w + $val['weight'] > 20)
{
$info[1]['weight'][] = (string)($w);
$w = $val['weight'];
}
else
$w += $val['weight'];
$val['product_quantity']--;
}
}
$info[1]['weight'][] = (string)($w);
if (date("N") == 5)
$next_day = date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+3, date("Y")));
elseif (date("N") == 6)
$next_day = date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+2, date("Y")));
else
$next_day = date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));
$newDate = Tools::getValue('dateErrorOrder');
$info[2] = array('delivery_date' => ($newDate != '' ? $newDate : $next_day));
if ($option)
$info[3] = array('option' => $option[0]['option']);
if (isset($dropOff))
$info[4] = $dropOff[0];
else
$info[4] = null;
return $info;
}
}
?>
+40
View File
@@ -0,0 +1,40 @@
<?php
class PackageTnt
{
private $_idOrder;
private $_order;
public function __construct($id_order)
{
$this->_idOrder = $id_order;
$this->_order = new Order((int)($this->_idOrder));
}
public function setShippingNumber($number)
{
if ($this->_order->shipping_number == '')
{
$this->_order->shipping_number = $number;
$this->_order->update();
}
$this->insertSql($number);
}
public function getShippingNumber()
{
$tab = Db::getInstance()->ExecuteS('SELECT `shipping_number` FROM `'._DB_PREFIX_.'tnt_carrier_shipping_number` WHERE `id_order` = "'.(int)($this->_idOrder).'"');
return ($tab);
}
public function insertSql($number)
{
Db::getInstance()->ExecuteS('INSERT INTO `'._DB_PREFIX_.'tnt_carrier_shipping_number` (`id_order`, `shipping_number`)
VALUES ("'.(int)($this->_idOrder).'", "'.$number.'")');
}
public function getOrder()
{
return ($this->_order);
}
}
@@ -0,0 +1,238 @@
<?php
class TntWebService
{
private $_login;
private $_password;
private $_account;
private $authheader;
private $authvars;
private $header;
private $file;
public function __construct()
{
$this->_login = Configuration::get('TNT_CARRIER_LOGIN');
$this->_password = Configuration::get('TNT_CARRIER_PASSWORD');
$this->_account = Configuration::get('TNT_CARRIER_NUMBER_ACCOUNT');
$this->_authheader = $this->genAuth();
$this->_authvars = new SoapVar($this->_authheader, XSD_ANYXML);
$this->_header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", $this->_authvars);
$this->_file = "http://www.tnt.fr/service/?wsdl";
}
public function genAuth()
{
return sprintf('
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>%s</wsse:Username>
<wsse:Password>%s</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>', htmlspecialchars($this->_login), htmlspecialchars($this->_password));
}
public function faisabilite($dateExpedition, $codePostalDepart, $communeDepart, $codePostalArrivee, $communeArrivee, $typeDestinataire)
{
$soapclient = new SoapClient($this->_file, array('trace'=>1));
$soapclient->__setSOAPHeaders(array($this->_header));
$sender = array("zipCode" => $codePostalDepart, "city" => $communeDepart);
$receiver = array("zipCode" => $codePostalArrivee, "city" => $communeArrivee, "type" => $typeDestinataire);
$parameters = array("accountNumber" => $this->_account, "shippingDate" => $dateExpedition, "sender" => $sender, "receiver" => $receiver);
$services = $soapclient->feasibility(array('parameters' => $parameters));
return ($services);
}
public function putCityInNormeTnt($city)
{
$city = iconv("utf-8", 'ASCII//TRANSLIT', $city);
$city = mb_strtoupper($city, 'utf-8');
$table = array('`' => '','\''=> '', '^' => '','À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B');
$city = strtr($city, $table);
$old = array("SAINT", "-");
$new = array("ST", " ");
return (str_replace($old, $new, $city));
}
public function getPackage($info)
{
$soapclient = new SoapClient($this->_file, array('trace'=>1));
$soapclient->__setSOAPHeaders(array($this->_header));
$sender = array(
'type' => (Configuration::get('TNT_CARRIER_SHIPPING_COLLECT') ? "ENTERPRISE" : "DEPOT"), //ENTREPRISE OR DEPOT
'typeId' => (Configuration::get('TNT_CARRIER_SHIPPING_COLLECT') ? "" : Configuration::get('TNT_CARRIER_SHIPPING_PEX')) , // code PEX if DEPOT is ON
'name' => Configuration::get('TNT_CARRIER_SHIPPING_COMPANY'), // raison social
'address1' => Configuration::get('TNT_CARRIER_SHIPPING_ADDRESS1'),
'address2' => Configuration::get('TNT_CARRIER_SHIPPING_ADDRESS2'),
'zipCode' => Configuration::get('TNT_CARRIER_SHIPPING_ZIPCODE'),
'city' => $this->putCityInNormeTnt(Configuration::get('TNT_CARRIER_SHIPPING_CITY')),
'contactLastName' => Configuration::get('TNT_CARRIER_SHIPPING_LASTNAME'),
'contactFirstName' => Configuration::get('TNT_CARRIER_SHIPPING_FIRSTNAME'),
'emailAddress' => Configuration::get('TNT_CARRIER_SHIPPING_EMAIL'),
'phoneNumber' => Configuration::get('TNT_CARRIER_SHIPPING_PHONE'),
'faxNumber' => '' //may be later
);
if ($info[4] == null)
$receiver = array(
'type' => ($info[0]['company'] != '' ? "ENTERPRISE" : 'INDIVIDUAL'), // ENTREPRISE DEPOT DROPOFFPOINT INDIVIDUAL
'typeId' => '', // IF DEPOT => code PEX else if DROPOFFPOINT => XETT
'name' => ($info[0]['company'] != '' ? $info[0]['company'] : ''),
'address1' => $info[0]['address1'],
'address2' => $info[0]['address2'],
'zipCode' => $info[0]['postcode'],
'city' => $this->putCityInNormeTnt($info[0]['city']),
'instructions' => '',
'contactLastName' => $info[0]['lastname'],
'contactFirstName' => $info[0]['firstname'],
'emailAddress' => $info[0]['email'],
'phoneNumber' => $info[0]['phone'],
'accessCode' => '',
'floorNumber' => '',
'buildingId' => '',
'sendNotification' => ''
);
else
$receiver = array(
'type' => 'DROPOFFPOINT', // ENTREPRISE DEPOT DROPOFFPOINT INDIVIDUAL
'typeId' => $info[4]['code'], // IF DEPOT => code PEX else if DROPOFFPOINT => XETT
'name' => $info[4]['name'],
'address1' => $info[4]['address'],
'address2' => '',
'zipCode' => $info[4]['zipcode'],
'city' => $info[4]['city'],
'instructions' => '',
'contactLastName' => $info[0]['lastname'],
'contactFirstName' => $info[0]['firstname'],
'emailAddress' => $info[0]['email'],
'phoneNumber' => $info[0]['phone'],
'accessCode' => '',
'floorNumber' => '',
'buildingId' => '',
'sendNotification' => ''
);
foreach ($info[1]['weight'] as $k => $v)
{
$parcelRequest[$k] = array(
'sequenceNumber' => $k + 1, // package number, there's only one at this moment
'customerReference' => $info[0]['id_customer'], // customer ref
'weight' => $v,
'insuranceAmount' => '',
'priorityGuarantee' => '',
'comment' => ''
);
}
$parcelsRequest = array('parcelRequest' => $parcelRequest);
$pickUpRequest = array(
'media' => "EMAIL",
'faxNumber' => "",
'emailAddress' => Configuration::get('TNT_CARRIER_SHIPPING_EMAIL'),
'notifySuccess' => "1",
'service' => "",
'lastName' => "",
'firstName' => "",
'phoneNumber' => Configuration::get('TNT_CARRIER_SHIPPING_PHONE'),
'closingTime' => Configuration::get('TNT_CARRIER_SHIPPING_CLOSING'),
'instructions' => ""
);
if (Configuration::get('TNT_CARRIER_SHIPPING_COLLECT') == 1)
{
$paremeters = array(
'pickUpRequest' => $pickUpRequest,
'shippingDate' => $info[2]['delivery_date'],
'accountNumber' => Configuration::get('TNT_CARRIER_NUMBER_ACCOUNT'),
'sender' => $sender,
'receiver' => $receiver,
'serviceCode' => $info[3]['option'],
'quantity' => count($info[1]['weight']), //number of package; count($parcelsRequest)
'parcelsRequest' => $parcelsRequest,
'saturdayDelivery' => '0',//Configuration::get('TNT_CARRIER_SHIPPING_DELIVERY'),
//'paybackInfo' => $paybackInfo,
'labelFormat' => (!Configuration::get('TNT_CARRIER_PRINT_STICKER') ? "STDA4" : Configuration::get('TNT_CARRIER_PRINT_STICKER'))
);
}
else
{
$paremeters = array(
'shippingDate' => $info[2]['delivery_date'],
'accountNumber' => Configuration::get('TNT_CARRIER_NUMBER_ACCOUNT'),
'sender' => $sender,
'receiver' => $receiver,
'serviceCode' => $info[3]['option'],
'quantity' => count($info[1]['weight']), //number of package; count($parcelsRequest)
'parcelsRequest' => $parcelsRequest,
'saturdayDelivery' => '0',//Configuration::get('TNT_CARRIER_SHIPPING_DELIVERY'),
//'paybackInfo' => $paybackInfo,
'labelFormat' => (!Configuration::get('TNT_CARRIER_PRINT_STICKER') ? "STDA4" : Configuration::get('TNT_CARRIER_PRINT_STICKER'))
);
}
$package = $soapclient->expeditionCreation(array('parameters' => $paremeters));
return $package;
}
public function followPackage($transport)
{
$soapclient = new SoapClient($this->_file, array('trace'=>1));
$soapclient->__setSOAPHeaders(array($this->_header));
$reponse = $soapclient->trackingByConsignment(array('parcelNumber' => $transport));
if (isset($reponse->Parcel) && $reponse->Parcel)
{
$colis = $reponse->Parcel;
$expediteur = $colis->sender;
$destinataire = $colis->receiver;
$evenements = $colis->events;
$requestDate = new DateTime($evenements->requestDate);
$processDate = new DateTime($evenements->processDate);
$arrivalDate = new DateTime($evenements->arrivalDate);
$deliveryDepartureDate = new DateTime($evenements->deliveryDepartureDate);
$deliveryDate = new DateTime($evenements->deliveryDate);
}
$packageParam = array(
'number' => (isset($colis->consignmentNumber) ? $colis->consignmentNumber : ''),
'status' => (isset($colis->shortStatus) ? $colis->shortStatus : ''),
'account_number' => (isset($colis->accountNumber) ? $colis->accountNumber : ''),
'service' => (isset($colis->service) ? $colis->service : ''),
'reference' => (isset($colis->reference) ? $colis->reference : ''),
'weight' => (isset($colis->weight) ? $colis->weight : ''),
'expediteur_name' => (isset($expediteur->name) ? $expediteur->name : ''),
'expediteur_addr1' => (isset($expediteur->address1) ? $expediteur->address1 : ''),
'expediteur_addr2' => (isset($expediteur->address2) ? $expediteur->address2 : ''),
'expediteur_zipcode' => (isset($expediteur->zipCode) ? $expediteur->zipCode : ''),
'expediteur_city' => (isset($expediteur->city) ? $expediteur->city : ''),
'destinataire_name' => (isset($destinataire->name) ? $destinataire->name : ''),
'destinataire_addr1' => (isset($destinataire->address1) ? $destinataire->address1 : ''),
'destinataire_addr2' => (isset($destinataire->address2) ? $destinataire->address2 : ''),
'destinataire_zipcode' => (isset($destinataire->zipCode) ? $destinataire->zipCode : ''),
'destinataire_city' => (isset($destinataire->city) ? $destinataire->city : ''),
'request' => (isset($evenements->requestDate) ? $evenements->requestDate : ''),
'requestDate' => (isset($requestDate) && isset($evenements->requestDate) ? $requestDate : ''),
'process' => (isset($evenements->processDate) ? $evenements->processDate : ''),
'process_date' => (isset($processDate) && isset($evenements->processDate) ? $processDate : ''),
'process_center' => (isset($evenements->processCenter) ? $evenements->processCenter : ''),
'arrival' => (isset($evenements->arrivalDepartureDate) ? $evenements->arrivalDepartureDate : ''),
'arrival_date' => (isset($arrivalDate) ? $arrivalDate : ''),
'arrival_center' => (isset($evenements->arrivalCenter) ? $evenements->arrivalCenter : ''),
'delivery_departure' => (isset($evenements->deliveryDepartureDate) ? $evenements->deliveryDepartureDate : ''),
'delivery_departure_date' => (isset($deliveryDepartureDate) ? $deliveryDepartureDate : ''),
'delivery_departure_center' => (isset($evenements->deliveryDepartureCenter) ? $evenements->deliveryDepartureCenter : ''),
'delivery' => (isset($evenements->deliveryDate) ? $evenements->deliveryDate : ''),
'delivery_date' => (isset($deliveryDate) ? $deliveryDate : ''),
'long_status' => (isset($colis->longStatus) ? $colis->longStatus : ''),
'linkPicture' => (isset($colis->primaryPODUrl) ? $colis->primaryPODUrl : '')
);
return $packageParam;
}
}
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6594 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../../../");
exit;
@@ -0,0 +1,58 @@
<?php
class serviceCache
{
private $_dateBefore;
private $_dateNow;
private $_idCard;
private $_zipCode;
public function __construct($id_card, $zipcode)
{
$this->_dateBefore = date("Y-m-d H:i:s", mktime(date("H"), date("i") - 15, date("s"), date("m") , date("d"), date("Y")));
$this->_dateNow = date('Y-m-d H:i:s');
$this->_idCard = $id_card;
$this->_zipCode = $zipcode;
}
public function getFaisabilityAtThisTime()
{
if (Db::getInstance()->getValue('SELECT * FROM `'._DB_PREFIX_.'tnt_carrier_cache_service` WHERE `date` >= "'.$this->_dateBefore.'" AND `date` <= "'.$this->_dateNow.'" AND id_card = "'.(int)($this->_idCard).'" AND zipcode = "'.$this->_zipCode.'"'))
return true;
return false;
}
public function deletePreviousServices()
{
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'tnt_carrier_cache_service` WHERE `id_card` = "'.(int)($this->_idCard).'"');
}
public static function deleteServices($idCard)
{
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'tnt_carrier_cache_service` WHERE `id_card` = "'.(int)($idCard).'"');
}
public function putInCache($service, $serviceRelais)
{
if (isset($service))
{
if (is_array($service->Service))
foreach ($service->Service as $k => $v)
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'tnt_carrier_cache_service` (`id_card`, `code`, `date`, `zipcode`) VALUES ("'.(int)($this->_idCard).'", "'.$v->serviceCode.'","'.$this->_dateNow.'", "'.$this->_zipCode.'")');
else
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'tnt_carrier_cache_service` (`id_card`, `code`, `date`, `zipcode`) VALUES ("'.(int)($this->_idCard).'", "'.$service->Service->serviceCode.'","'.$this->_dateNow.'", "'.$this->_zipCode.'")');
}
if (isset($serviceRelais))
{
foreach ($serviceRelais as $v)
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'tnt_carrier_cache_service` (`id_card`, `code`, `date`, `zipcode`) VALUES ("'.(int)($this->_idCard).'", "'.$v->serviceCode.'","'.$this->_dateNow.'", "'.$this->_zipCode.'")');
}
}
public function getServices()
{
return (Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'tnt_carrier_cache_service` WHERE id_card = "'.(int)($this->_idCard).'"'));
}
}
?>