This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
<?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: 6844 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__).'/../errorCode.php');
|
||||
require_once(realpath(dirname(__FILE__).'/../mondialrelay.php'));
|
||||
require_once(realpath(dirname(__FILE__).'/../lib/nusoap/nusoap.php'));
|
||||
|
||||
/*
|
||||
* This method allow to create any method object to dial more
|
||||
* easyly with the Mondial Reelay WebService
|
||||
*/
|
||||
interface IMondialRelayWSMethod
|
||||
{
|
||||
/*
|
||||
* Initiate the data needed to be send properly
|
||||
* Can manage a list of data for multiple request
|
||||
*/
|
||||
public function init();
|
||||
|
||||
/*
|
||||
* Send one or multiple request to the webservice
|
||||
*/
|
||||
public function send();
|
||||
|
||||
/*
|
||||
* Get the values with associated fields name
|
||||
*/
|
||||
public function getFieldsList();
|
||||
|
||||
/*
|
||||
* Get the result of one or multiple send request
|
||||
*/
|
||||
public function getResult();
|
||||
}
|
||||
|
||||
?>
|
||||
+527
@@ -0,0 +1,527 @@
|
||||
<?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: 7310 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Interface
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/IMondialRelayWSMethod.php');
|
||||
|
||||
/*
|
||||
* Allow to create tickets - 'WSI2_CreationEtiquette'
|
||||
*/
|
||||
class MRCreateTickets implements IMondialRelayWSMethod
|
||||
{
|
||||
private $_fields = array(
|
||||
'id_mr_selected' => 0,
|
||||
'list' => array(
|
||||
'Enseigne' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{2}[0-9A-Z ]{6}$#'),
|
||||
'ModeCol' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(CCC|CDR|CDS|REL)$#'),
|
||||
'ModeLiv' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(LCC|LDR|LDS|24R|ESP|DRI)$#'),
|
||||
'NDossier' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9A-Z_ -]{0,15})$#'),
|
||||
'NClient' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9A-Z]{0,9})$#'),
|
||||
'Expe_Langage' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Expe_Ad1' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{2,32}$#'),
|
||||
'Expe_Ad2' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{0,32}$#'),
|
||||
'Expe_Ad3' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{0,32}$#'),
|
||||
'Expe_Ad4' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{2}[0-9A-Z ]{6}$#'),
|
||||
'Expe_Ville' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z_\-\' ]{2,26}$#'),
|
||||
'Expe_CP' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{5}$#'),
|
||||
'Expe_Pays' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Expe_Tel1' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^((00|\+)33|0)[0-9][0-9]{8}$#'),
|
||||
'Expe_Tel2' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^((00|\+)33|0)[0-9][0-9]{8}$#'),
|
||||
'Expe_Mail' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[\w\-\.\@_]{0,70}$#'),
|
||||
'Dest_Langage' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Dest_Ad1' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{2,32}$#'),
|
||||
'Dest_Ad2' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{2,32}$#'),
|
||||
'Dest_Ad3' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{2,32}$#'),
|
||||
'Dest_Ad4' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{0,32}$#'),
|
||||
'Dest_Ville' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z_\-\' ]{2,26}$#'),
|
||||
'Dest_CP' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{5}$#'),
|
||||
'Dest_Pays' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Dest_Tel1' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^((00|\+)33|0)[0-9][0-9]{8}$#'),
|
||||
'Dest_Tel2' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^((00|\+)33|0)[0-9][0-9]{8}$#'),
|
||||
'Dest_Mail' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[\w\-\.\@_]{0,70}$#'),
|
||||
'Poids' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{3,7}$#'),
|
||||
'Longueur' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{0,3}$#'),
|
||||
'Taille' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(XS|S|M|L|XL|XXL|3XL)$#'),
|
||||
'NbColis' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{1,2}$#'),
|
||||
'CRT_Valeur' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{1,7}$#'),
|
||||
'CRT_Devise' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|EUR)$#'),
|
||||
'Exp_Valeur' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{0,7}$#'),
|
||||
'Exp_Devise' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|EUR)$#'),
|
||||
'COL_Rel_Pays' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'COL_Rel' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9]{6})$#'),
|
||||
'LIV_Rel_Pays' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'LIV_Rel' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9]{6})$#'),
|
||||
'TAvisage' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|O|N)$#'),
|
||||
'TReprise' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|O|N)$#'),
|
||||
'Montage' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9]{1,3})$#'),
|
||||
'TRDV' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|O|N)$#'),
|
||||
'Assurance' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(|[0-9A-Z]{1})$#'),
|
||||
'Instructions' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z_\-\'., /]{0,31}#'),
|
||||
'Security' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{32}$#'),
|
||||
'Texte' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^([^<>&\']{3,30})(\(cr\)[^<>&\']{0,30}){0,9}$#')));
|
||||
|
||||
private $_orderListId = NULL;
|
||||
private $_totalOrder = 0;
|
||||
private $_weightList = NULL;
|
||||
private $_mondialRelay = NULL;
|
||||
private $_fieldsList = array();
|
||||
private $_webServiceKey = '';
|
||||
private $_markCode = '';
|
||||
|
||||
private $_resultList = array(
|
||||
'error' => array(),
|
||||
'success' => array());
|
||||
|
||||
private $_webserviceURL = 'http://www.mondialrelay.fr/webservice/Web_Services.asmx?WSDL';
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->_orderListId = $params['orderIdList'];
|
||||
$this->_totalOrder = $params['totalOrder'];
|
||||
$this->_weightList = $params['weightList'];
|
||||
$this->_webServiceKey = Configuration::get('MR_KEY_WEBSERVICE');
|
||||
$this->_markCode = Configuration::get('MR_CODE_MARQUE');
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->_mondialRelay);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a correct weight format (NNNNN)
|
||||
*/
|
||||
private function _weightFormat($weight)
|
||||
{
|
||||
while (strlen($weight) != 5)
|
||||
$weight = '0'.$weight;
|
||||
return $weight;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the default value to the order paramaters
|
||||
*/
|
||||
private function _setRequestDefaultValue()
|
||||
{
|
||||
$this->_fields['list']['Enseigne']['value'] = Configuration::get('MR_ENSEIGNE_WEBSERVICE');
|
||||
$this->_fields['list']['Expe_Langage']['value'] = Configuration::get('MR_LANGUAGE');
|
||||
$this->_fields['list']['Expe_Ad1']['value'] = Configuration::get('PS_MR_SHOP_NAME');
|
||||
$this->_fields['list']['Expe_Ad3']['value'] = Configuration::get('PS_SHOP_ADDR1');
|
||||
$this->_fields['list']['Expe_Ad4']['value'] = Configuration::get('PS_SHOP_ADDR2');
|
||||
$this->_fields['list']['Expe_Ville']['value'] = Configuration::get('PS_SHOP_CITY');
|
||||
$this->_fields['list']['Expe_CP']['value'] = Configuration::get('PS_SHOP_CODE');
|
||||
|
||||
if (_PS_VERSION_ >= '1.4')
|
||||
$this->_fields['list']['Expe_Pays']['value'] = Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID'));
|
||||
else
|
||||
$this->_fields['list']['Expe_Pays']['value'] = substr(Configuration::get('PS_SHOP_COUNTRY'), 0, 2);
|
||||
|
||||
$this->_fields['list']['Expe_Tel1']['value'] = Configuration::get('PS_SHOP_PHONE');
|
||||
$this->_fields['list']['Expe_Mail']['value'] = Configuration::get('PS_SHOP_EMAIL');
|
||||
$this->_fields['list']['NbColis']['value'] = 1;
|
||||
$this->_fields['list']['CRT_Valeur']['value'] = 0;
|
||||
$this->_fields['list']['CRT_Devise']['value'] = 'EUR';
|
||||
}
|
||||
|
||||
/*
|
||||
* Initiate the data needed to be send properly
|
||||
* Can manage a list of data for multiple request
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->_mondialRelay = new MondialRelay();
|
||||
|
||||
if ($this->_totalOrder == 0)
|
||||
throw new Exception($this->_mondialRelay->l('Please select at least one order'));
|
||||
|
||||
$this->_setRequestDefaultValue();
|
||||
if (count($orderListDetails = $this->_mondialRelay->getOrders($this->_orderListId)))
|
||||
{
|
||||
foreach ($orderListDetails as $orderDetail)
|
||||
{
|
||||
// Storage temporary
|
||||
$base = $this->_fields;
|
||||
$tmp = &$base['list'];
|
||||
|
||||
$deliveriesAddress = new Address($orderDetail['id_address_delivery']);
|
||||
$customer = new Customer($orderDetail['id_customer']);
|
||||
|
||||
// Store the weight order set by the user
|
||||
foreach($this->_weightList as $orderWeightInfos)
|
||||
{
|
||||
$detail = explode('-', $orderWeightInfos);
|
||||
if (count($detail) == 2 && $detail[1] == $orderDetail['id_order'])
|
||||
$tmp['Poids']['value'] = $this->_weightFormat($detail[0]);
|
||||
}
|
||||
|
||||
$destIsoCode = Country::getIsoById($deliveriesAddress->id_country);
|
||||
$tmp['ModeCol']['value'] = $orderDetail['mr_ModeCol'];
|
||||
$tmp['ModeLiv']['value'] = $orderDetail['mr_ModeLiv'];
|
||||
$tmp['NDossier']['value'] = $orderDetail['id_order'];
|
||||
$tmp['NClient']['value'] = $orderDetail['id_customer'];
|
||||
$tmp['Dest_Langage']['value'] = $destIsoCode;
|
||||
$tmp['Dest_Ad1']['value'] = $deliveriesAddress->lastname;
|
||||
$tmp['Dest_Ad2']['value'] = $deliveriesAddress->address2;
|
||||
$tmp['Dest_Ad3']['value'] = $deliveriesAddress->address1;
|
||||
$tmp['Dest_Ville']['value'] = $deliveriesAddress->city;
|
||||
$tmp['Dest_CP']['value'] = $deliveriesAddress->postcode;
|
||||
$tmp['Dest_Pays']['value'] = $destIsoCode;
|
||||
$tmp['Dest_Tel1']['value'] = $deliveriesAddress->phone;
|
||||
$tmp['Dest_Tel2']['value'] = $deliveriesAddress->phone_mobile;
|
||||
$tmp['Dest_Mail']['value'] = $customer->email;
|
||||
$tmp['Assurance']['value'] = $orderDetail['mr_ModeAss'];
|
||||
|
||||
if ($orderDetail['MR_Selected_Num'] != 'LD1' && $orderDetail['MR_Selected_Num'] != 'LDS')
|
||||
{
|
||||
$tmp['LIV_Rel_Pays']['value'] = $orderDetail['MR_Selected_Pays'];
|
||||
$tmp['LIV_Rel']['value'] = $orderDetail['MR_Selected_Num'];
|
||||
}
|
||||
|
||||
// Store the necessary information to the root case table
|
||||
$base['id_mr_selected'] = $orderDetail['id_mr_selected'];
|
||||
|
||||
// Add the temporary values to a field list for multiple request
|
||||
$this->_fieldsList[] = $base;
|
||||
unset($deliveriesAddress);
|
||||
unset($customer);
|
||||
}
|
||||
$this->_generateMD5SecurityKey();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the MD5 key for each param list
|
||||
*/
|
||||
private function _generateMD5SecurityKey()
|
||||
{
|
||||
// RootCase is the array case where the main information are stored
|
||||
// it's an array containing id_mr_selected and an array with the necessary fields
|
||||
foreach($this->_fieldsList as &$rootCase)
|
||||
{
|
||||
$concatenationValue = '';
|
||||
foreach($rootCase['list'] as $paramName => &$valueDetailed)
|
||||
if ($paramName != 'Texte' && $paramName != 'Security')
|
||||
{
|
||||
$valueDetailed['value'] = strtoupper(MRManagement::replaceAccentedCharacters($valueDetailed['value']));
|
||||
if (preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
else if ((!strlen($valueDetailed['value']) && $valueDetailed['required']) || strlen($valueDetailed['value']))
|
||||
{
|
||||
if (empty($valueDetailed['value']))
|
||||
$error = $this->_mondialRelay->l('This key').' ['.$paramName.'] '.$this->_mondialRelay->l('is empty and need to be filled');
|
||||
else
|
||||
$error = 'This key ['.$paramName.'] hasn\'t a valid value format : '.$valueDetailed['value'];
|
||||
$this->_resultList['error'][$rootCase['list']['NDossier']['value']][] = $error;
|
||||
}
|
||||
}
|
||||
$concatenationValue .= $this->_webServiceKey;
|
||||
$rootCase['list']['Security']['value' ] = strtoupper(md5($concatenationValue));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the tables used and send mail with the order history
|
||||
*/
|
||||
private function _updateTable($params, $expeditionNum, $ticketURL, $trackingURL, $id_mr_selected)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'mr_selected`
|
||||
SET `MR_poids` = \''.$params['Poids'].'\',
|
||||
`exp_number` = \''.$expeditionNum.'\',
|
||||
`url_etiquette` = \''.$ticketURL.'\',
|
||||
`url_suivi` = \''.$trackingURL.'\'
|
||||
WHERE id_mr_selected = '.(int)$id_mr_selected);
|
||||
|
||||
// NDossier contains the id_order
|
||||
$order = new Order($params['NDossier']);
|
||||
|
||||
// Update the database for order and orderHistory
|
||||
$order->shipping_number = $id_mr_selected;
|
||||
$order->update();
|
||||
|
||||
$templateVars = array('{followup}' => $trackingURL);
|
||||
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int)($params['NDossier']);
|
||||
$history->changeIdOrderState(_PS_OS_SHIPPING_, (int)($params['NDossier']));
|
||||
$history->id_employee = (int)($cookie->id_employee);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
|
||||
unset($order);
|
||||
unset($history);
|
||||
}
|
||||
|
||||
/*
|
||||
* Manage the return value of the webservice, handle the errors or build the
|
||||
* succeed message
|
||||
*/
|
||||
private function _parseResult($client, $result, $params, $id_mr_selected)
|
||||
{
|
||||
$errors = &$this->_resultList['error'][$params['NDossier']];
|
||||
$success = &$this->_resultList['success'][$params['NDossier']];
|
||||
|
||||
if ($client->fault)
|
||||
$errors[] = $this->_mondialRelay->l('It seems the request isn\'t valid:').
|
||||
$result;
|
||||
|
||||
$result = $result['WSI2_CreationEtiquetteResult'];
|
||||
if (($errorNumber = $result['STAT']) != 0)
|
||||
{
|
||||
$errors[] = $this->_mondialRelay->l('There is an error number : ').$errorNumber;
|
||||
$errors[] = $this->_mondialRelay->l('Details : ').
|
||||
$this->_mondialRelay->getErrorCodeDetail($errorNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
$baseURL = 'http://www.mondialrelay.fr/';
|
||||
$expedition = $result['ExpeditionNum'];
|
||||
$securityKey = strtoupper(md5('<'.$params['Enseigne'].$this->_markCode.
|
||||
'>'.$expedition.'<'.$this->_webServiceKey.'>'));
|
||||
$ticketURL = $baseURL.$result['URL_Etiquette'];
|
||||
$trackingURL = $baseURL.
|
||||
'lg_fr/espaces/url/popup_exp_details.aspx?cmrq='.$params['Enseigne'].
|
||||
$this->_markCode.'&nexp='.$expedition.'&crc='.$securityKey;
|
||||
|
||||
$success['displayExpedition'] = $this->_mondialRelay->l('Expedition Number : ') . $expedition;
|
||||
$success['displayTicketURL'] = $this->_mondialRelay->l('Ticket URL : ') . $ticketURL;
|
||||
$success['displayTrackingURL'] = $this->_mondialRelay->l('Tracking URL: ') . $trackingURL;
|
||||
$success['expeditionNumber'] = $expedition;
|
||||
|
||||
$this->_updateTable($params, $expedition, $ticketURL, $trackingURL, $id_mr_selected);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send one or multiple request to the webservice
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
if ($client = new nusoap_client($this->_webserviceURL, true))
|
||||
{
|
||||
$client->soap_defencoding = 'UTF-8';
|
||||
$client->decode_utf8 = false;
|
||||
|
||||
foreach($this->_fieldsList as $rootCase)
|
||||
{
|
||||
$params = $this->_getSimpleParamArray($rootCase['list']);
|
||||
$result = $client->call(
|
||||
'WSI2_CreationEtiquette',
|
||||
$params,
|
||||
'http://www.mondialrelay.fr/webservice/',
|
||||
'http://www.mondialrelay.fr/webservice/WSI2_CreationEtiquette');
|
||||
|
||||
$this->_parseResult($client, $result, $params, $rootCase['id_mr_selected']);
|
||||
}
|
||||
unset($client);
|
||||
}
|
||||
else
|
||||
throw new Exception($this->_mondialRelay->l('The Mondial Relay webservice isn\'t currently reliable'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the values with associated fields name
|
||||
* @fields : array containing multiple values information
|
||||
*/
|
||||
private function _getSimpleParamArray($fields)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
foreach($fields as $keyName => $valueDetailed)
|
||||
$params[$keyName] = $valueDetailed['value'];
|
||||
return $params;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the fields list
|
||||
*/
|
||||
public function getFieldsList()
|
||||
{
|
||||
return $this->_fieldsList['list'];
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the result of one or multiple sent requests
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return $this->_resultList;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return which number order of the list is currently managed
|
||||
*/
|
||||
static public function getCurrentRequestUnderTraitment()
|
||||
{
|
||||
// TODO: Build a SQL Query to know how many request have been executed
|
||||
}
|
||||
}
|
||||
?>
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
<?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: 7310 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Interface
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/IMondialRelayWSMethod.php');
|
||||
|
||||
/*
|
||||
* Allow to retrieve tickets - 'WSI2_GetEtiquettes'
|
||||
*/
|
||||
class MRGetTickets implements IMondialRelayWSMethod
|
||||
{
|
||||
private $_fields = array(
|
||||
'list' => array(
|
||||
'Enseigne' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{2}[0-9A-Z ]{6}$#'),
|
||||
'Expeditions' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{8}(;[0-9]{8})*$#'),
|
||||
'Langue' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Security' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{32}$#')));
|
||||
|
||||
private $_detailedExpeditionList = array();
|
||||
private $_webServiceKey = '';
|
||||
private $_markCode = '';
|
||||
private $_mondialRelay = NULL;
|
||||
|
||||
private $_resultList = array(
|
||||
'error' => array(),
|
||||
'success' => array());
|
||||
|
||||
private $_webserviceURL = 'http://www.mondialrelay.fr/webservice/Web_Services.asmx?WSDL';
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->_detailedExpeditionList = $params['detailedExpeditionList'];
|
||||
$this->_webServiceKey = Configuration::get('MR_KEY_WEBSERVICE');
|
||||
$this->_markCode = Configuration::get('MR_CODE_MARQUE');
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->_mondialRelay);
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_mondialRelay = new MondialRelay();
|
||||
|
||||
$this->_fields['list']['Enseigne']['value'] = Configuration::get('MR_ENSEIGNE_WEBSERVICE');
|
||||
$this->_fields['list']['Langue']['value'] = Configuration::get('MR_LANGUAGE');
|
||||
|
||||
foreach ($this->_detailedExpeditionList as $detailedExpedition)
|
||||
{
|
||||
// Storage temporary
|
||||
$base = $this->_fields;
|
||||
$tmp = &$base['list'];
|
||||
|
||||
$tmp['Expeditions']['value'] = $detailedExpedition['expeditionNumber'];
|
||||
$this->_fieldsList[] = $base;
|
||||
}
|
||||
$this->_generateMD5SecurityKey();
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the MD5 key for each param list
|
||||
*/
|
||||
private function _generateMD5SecurityKey()
|
||||
{
|
||||
// RootCase is the array case where the main information are stored
|
||||
// it's an array containing id_mr_selected and an array with the necessary fields
|
||||
foreach($this->_fieldsList as &$rootCase)
|
||||
{
|
||||
$concatenationValue = '';
|
||||
foreach($rootCase['list'] as $paramName => &$valueDetailed)
|
||||
if ($paramName != 'Texte' && $paramName != 'Security')
|
||||
{
|
||||
$valueDetailed['value'] = strtoupper($valueDetailed['value']);
|
||||
if (preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
else if ((!strlen($valueDetailed['value']) && $valueDetailed['required']) || strlen($valueDetailed['value']))
|
||||
{
|
||||
$error = $this->_mondialRelay->l('This key').' ['.$paramName.'] '.$this->_mondialRelay->l('hasn\'t a valide value format').' : '.$valueDetailed['value'];
|
||||
$id_order = $this->_getOrderIdWithExpeditionNumber($rootCase['list']['Expeditions']['value']);
|
||||
$this->_resultList['error'][$id_order][] = $error;
|
||||
}
|
||||
}
|
||||
$concatenationValue .= $this->_webServiceKey;
|
||||
$rootCase['list']['Security']['value' ] = strtoupper(md5($concatenationValue));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the values with associated fields name
|
||||
* @fields : array containing multiple values information
|
||||
*/
|
||||
private function _getSimpleParamArray($fields)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
foreach($fields as $keyName => $valueDetailed)
|
||||
$params[$keyName] = $valueDetailed['value'];
|
||||
return $params;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the history tables
|
||||
*/
|
||||
private function _updateTable($id_order, $expeditionNumber, $URLA4, $URLA5, &$success)
|
||||
{
|
||||
$query = '
|
||||
SELECT id FROM `'._DB_PREFIX_.'mr_historique`
|
||||
WHERE `order`=\''.$id_order.'\'';
|
||||
|
||||
$row = Db::getInstance()->getRow($query);
|
||||
if ($row)
|
||||
{
|
||||
$query = '
|
||||
UPDATE `'._DB_PREFIX_.'mr_historique`
|
||||
SET
|
||||
`exp` = \''.(int)$expeditionNumber.'\',
|
||||
`url_a4` = \''.(string)$URLA4.'\',
|
||||
`url_a5` = \''.(string)$URLA5.'\'
|
||||
WHERE `order` = \''.$id_order.'\'';
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = '
|
||||
INSERT INTO '._DB_PREFIX_.'mr_historique
|
||||
(`order`, `exp`, `url_a4`, `url_a5`)
|
||||
VALUES (
|
||||
\''.(int)$id_order.'\',
|
||||
\''.(int)$expeditionNumber.'\',
|
||||
\''.(string)$URLA4.'\',
|
||||
\''.(string)$URLA5.'\')';
|
||||
}
|
||||
Db::getInstance()->Execute($query);
|
||||
$success['id_mr_history'] = isset($row['id']) ? $row['id'] : Db::getInstance()->Insert_ID();
|
||||
}
|
||||
|
||||
/*
|
||||
* Manage the return value of the webservice, handle the errors or build the
|
||||
* succeed message
|
||||
*/
|
||||
private function _parseResult($client, $result, $params)
|
||||
{
|
||||
$errors = array();
|
||||
$success = array();
|
||||
|
||||
$id_order = $this->_getOrderIdWithExpeditionNumber($params['Expeditions']);
|
||||
if ($client->fault)
|
||||
$errors[$errorTotal++] = $this->_mondialRelay->l('It seems the request isn\'t valid:').
|
||||
$result;
|
||||
|
||||
$result = $result['WSI2_GetEtiquettesResult'];
|
||||
if (($errorNumber = $result['STAT']) != 0)
|
||||
{
|
||||
$errors[] = $this->_mondialRelay->l('There is an error number : ').$errorNumber;
|
||||
$errors[] = $this->_mondialRelay->l('Details : ').
|
||||
$this->_mondialRelay->getErrorCodeDetail($errorNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
$baseURL = 'http://www.mondialrelay.fr';
|
||||
$URLPDF_A4 = $baseURL.$result['URL_PDF_A4'];
|
||||
$URLPDF_A5 = $baseURL.$result['URL_PDF_A5'];
|
||||
|
||||
$success['id_order'] = $id_order;
|
||||
$success['expeditionNumber'] = $params['Expeditions'];
|
||||
$success['URLPDF_A4'] = $URLPDF_A4;
|
||||
$success['URLPDF_A5'] = $URLPDF_A5;
|
||||
$this->_updateTable($id_order, $params['Expeditions'], $URLPDF_A4, $URLPDF_A5, $success);
|
||||
}
|
||||
$this->_resultList['error'][$id_order] = $errors;
|
||||
$this->_resultList['success'][$id_order] = $success;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the order id using the expedition number
|
||||
*/
|
||||
private function _getOrderIdWithExpeditionNumber($expeditionNumber)
|
||||
{
|
||||
foreach($this->_detailedExpeditionList as $detailedExpedition)
|
||||
if ($detailedExpedition['expeditionNumber'] == $expeditionNumber)
|
||||
return $detailedExpedition['id_order'];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send one or multiple request to the webservice
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
if ($client = new nusoap_client($this->_webserviceURL, true))
|
||||
{
|
||||
$client->soap_defencoding = 'UTF-8';
|
||||
$client->decode_utf8 = false;
|
||||
|
||||
foreach($this->_fieldsList as $rootCase)
|
||||
{
|
||||
$params = $this->_getSimpleParamArray($rootCase['list']);
|
||||
$result = $client->call(
|
||||
'WSI2_GetEtiquettes',
|
||||
$params,
|
||||
'http://www.mondialrelay.fr/webservice/',
|
||||
'http://www.mondialrelay.fr/webservice/WSI2_GetEtiquettes');
|
||||
|
||||
$this->_parseResult($client, $result, $params);
|
||||
}
|
||||
unset($client);
|
||||
}
|
||||
else
|
||||
throw new Exception($this->_mondialRelay->l('The Mondial Relay webservice isn\'t currently reliable'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the values with associated fields name
|
||||
*/
|
||||
public function getFieldsList()
|
||||
{
|
||||
return $this->_fieldsList['list'];
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the result of one or multiple send request
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return $this->_resultList;
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<?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: 6844 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
require_once(realpath(dirname(__FILE__).'/../mondialrelay.php'));
|
||||
|
||||
class MRManagement extends MondialRelay
|
||||
{
|
||||
private $_params = array();
|
||||
|
||||
private $_resultList = array(
|
||||
'error' => array(),
|
||||
'success' => array());
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->_params = $params;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static public function replaceAccentedCharacters($string)
|
||||
{
|
||||
$currentLocale = setlocale(LC_ALL, NULL);
|
||||
setlocale(LC_ALL, 'en_US.UTF8');
|
||||
$cleanedString = iconv('UTF-8','ASCII//TRANSLIT', $string);
|
||||
setLocale(LC_ALL, $currentLocale);
|
||||
return $cleanedString;
|
||||
}
|
||||
|
||||
/*
|
||||
** Retro compatibility for 1.3
|
||||
** This method fill the database with the selected carrier
|
||||
*/
|
||||
public function addSelectedCarrierToDB()
|
||||
{
|
||||
$this->hookProcessCarrier($this->_params, false);
|
||||
}
|
||||
|
||||
public function DeleteHistory()
|
||||
{
|
||||
$success = array();
|
||||
$error = array();
|
||||
|
||||
if (is_array($this->_params['historyIdList']) && count($this->_params['historyIdList']))
|
||||
{
|
||||
$query = '
|
||||
DELETE FROM `'._DB_PREFIX_.'mr_historique`
|
||||
WHERE id IN(';
|
||||
foreach($this->_params['historyIdList'] as $id)
|
||||
$query .= (int)$id.', ';
|
||||
$query = trim($query, ', ').')';
|
||||
|
||||
$success['deletedListId'] = $this->_params['historyIdList'];
|
||||
$totalDeleted = Db::getInstance()->Execute($query);
|
||||
if (count($success['deletedListId']) != $totalDeleted)
|
||||
{
|
||||
$error[] = $this->l('Some items can\'t be removed, please try to remove it again');
|
||||
foreach($success['deletedListId'] as $id)
|
||||
{
|
||||
$query = '
|
||||
SELECT id FROM `'._DB_PREFIX_.'mr_historique`
|
||||
WHERE id='.(int)$id;
|
||||
if (Db::getInstance()->getRow($query) &&
|
||||
($key = array_search($id, $success['deletedListId'])) !== FALSE)
|
||||
unset($success['deletedListId'][$key]);
|
||||
}
|
||||
}
|
||||
$this->_resultList['success'] = $success;
|
||||
$this->_resultList['other']['error'] = $error;
|
||||
}
|
||||
else
|
||||
throw new Exception($this->l('Please select at least one history element'));
|
||||
return $this->_resultList;
|
||||
}
|
||||
}
|
||||
?>
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?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: 6844 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class MondialRelayClass extends ObjectModel
|
||||
{
|
||||
public $id_customer;
|
||||
public $id_method;
|
||||
public $id_cart;
|
||||
public $id_order = NULL;
|
||||
public $MR_poids = NULL;
|
||||
public $MR_Selected_Num;
|
||||
public $MR_Selected_LgAdr1;
|
||||
public $MR_Selected_LgAdr2 = NULL;
|
||||
public $MR_Selected_LgAdr3;
|
||||
public $MR_Selected_LgAdr4 = NULL;
|
||||
public $MR_Selected_CP;
|
||||
public $MR_Selected_Ville;
|
||||
public $MR_Selected_Pays;
|
||||
public $url_suivi= NULL;
|
||||
public $url_etiquette= NULL;
|
||||
public $exp_number= NULL;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
|
||||
|
||||
protected $table = 'mr_selected';
|
||||
protected $identifier = 'id_mr_selected';
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
if (isset($this->id_mr_selected))
|
||||
$fields['id_mr_selected'] = (int)($this->id_mr_selected);
|
||||
|
||||
$fields['id_customer'] = (int)($this->id_customer);
|
||||
$fields['id_method'] = (int)($this->id_method);
|
||||
$fields['id_cart'] = (int)($this->id_cart);
|
||||
$fields['id_order'] = is_null($this->id_order) ? 0 : (int)($this->id_order);
|
||||
$fields['MR_Selected_Num'] = pSQL($this->MR_Selected_Num);
|
||||
$fields['MR_Selected_LgAdr1'] = pSQL($this->MR_Selected_LgAdr1);
|
||||
$fields['MR_Selected_LgAdr2'] = pSQL($this->MR_Selected_LgAdr2);
|
||||
$fields['MR_Selected_LgAdr3'] = pSQL($this->MR_Selected_LgAdr3);
|
||||
$fields['MR_Selected_LgAdr4'] = pSQL($this->MR_Selected_LgAdr4);
|
||||
$fields['MR_Selected_CP'] = (int)($this->MR_Selected_CP);
|
||||
$fields['MR_Selected_Ville'] = pSQL($this->MR_Selected_Ville);
|
||||
$fields['MR_Selected_Pays'] = pSQL($this->MR_Selected_Pays);
|
||||
$fields['url_suivi'] = is_null($this->url_suivi) ? 0 : pSQL($this->url_suivi) ;
|
||||
$fields['url_etiquette'] = is_null($this->url_etiquette) ? 0 : pSQL($this->url_etiquette) ;
|
||||
$fields['exp_number'] = is_null($this->exp_number) ? 0 : pSQL($this->exp_number) ;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['MR_poids'] = is_null($this->MR_poids) ? 0 : pSQL($this->MR_poids) ;
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user