// Merge with revision 7841
This commit is contained in:
Executable
+314
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
|
||||
*
|
||||
* This is a direct port of jsmin.c to PHP with a few PHP performance tweaks and
|
||||
* modifications to preserve some comments (see below). Also, rather than using
|
||||
* stdin/stdout, JSMin::minify() accepts a string as input and returns another
|
||||
* string as output.
|
||||
*
|
||||
* Comments containing IE conditional compilation are preserved, as are multi-line
|
||||
* comments that begin with "/*!" (for documentation purposes). In the latter case
|
||||
* newlines are inserted around the comment to enhance readability.
|
||||
*
|
||||
* PHP 5 or higher is required.
|
||||
*
|
||||
* Permission is hereby granted to use this version of the library under the
|
||||
* same terms as jsmin.c, which has the following license:
|
||||
*
|
||||
* --
|
||||
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* The Software shall be used for Good, not Evil.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* --
|
||||
*
|
||||
* @package JSMin
|
||||
* @author Ryan Grove <ryan@wonko.com> (PHP port)
|
||||
* @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
|
||||
* @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
|
||||
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
||||
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
||||
* @license http://opensource.org/licenses/mit-license.php MIT License
|
||||
* @link http://code.google.com/p/jsmin-php/
|
||||
*/
|
||||
|
||||
class JSMin {
|
||||
const ORD_LF = 10;
|
||||
const ORD_SPACE = 32;
|
||||
const ACTION_KEEP_A = 1;
|
||||
const ACTION_DELETE_A = 2;
|
||||
const ACTION_DELETE_A_B = 3;
|
||||
|
||||
protected $a = "\n";
|
||||
protected $b = '';
|
||||
protected $input = '';
|
||||
protected $inputIndex = 0;
|
||||
protected $inputLength = 0;
|
||||
protected $lookAhead = null;
|
||||
protected $output = '';
|
||||
|
||||
/**
|
||||
* Minify Javascript
|
||||
*
|
||||
* @param string $js Javascript to be minified
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($js)
|
||||
{
|
||||
$jsmin = new JSMin($js);
|
||||
return $jsmin->min();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup process
|
||||
*/
|
||||
public function __construct($input)
|
||||
{
|
||||
$this->input = str_replace("\r\n", "\n", $input);
|
||||
$this->inputLength = strlen($this->input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform minification, return result
|
||||
*/
|
||||
public function min()
|
||||
{
|
||||
if ($this->output !== '') { // min already run
|
||||
return $this->output;
|
||||
}
|
||||
$this->action(self::ACTION_DELETE_A_B);
|
||||
|
||||
while ($this->a !== null) {
|
||||
// determine next command
|
||||
$command = self::ACTION_KEEP_A; // default
|
||||
if ($this->a === ' ') {
|
||||
if (! $this->isAlphaNum($this->b)) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
} elseif ($this->a === "\n") {
|
||||
if ($this->b === ' ') {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
} elseif (false === strpos('{[(+-', $this->b)
|
||||
&& ! $this->isAlphaNum($this->b)) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
} elseif (! $this->isAlphaNum($this->a)) {
|
||||
if ($this->b === ' '
|
||||
|| ($this->b === "\n"
|
||||
&& (false === strpos('}])+-"\'', $this->a)))) {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
}
|
||||
}
|
||||
$this->action($command);
|
||||
}
|
||||
$this->output = trim($this->output);
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
||||
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
||||
* ACTION_DELETE_A_B = Get the next B.
|
||||
*/
|
||||
protected function action($command)
|
||||
{
|
||||
switch ($command) {
|
||||
case self::ACTION_KEEP_A:
|
||||
$this->output .= $this->a;
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A:
|
||||
$this->a = $this->b;
|
||||
if ($this->a === "'" || $this->a === '"') { // string literal
|
||||
$str = $this->a; // in case needed for exception
|
||||
while (true) {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
if ($this->a === $this->b) { // end quote
|
||||
break;
|
||||
}
|
||||
if (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMin_UnterminatedStringException(
|
||||
'Unterminated String: ' . var_export($str, true));
|
||||
}
|
||||
$str .= $this->a;
|
||||
if ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$str .= $this->a;
|
||||
}
|
||||
}
|
||||
}
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A_B:
|
||||
$this->b = $this->next();
|
||||
if ($this->b === '/' && $this->isRegexpLiteral()) { // RegExp literal
|
||||
$this->output .= $this->a . $this->b;
|
||||
$pattern = '/'; // in case needed for exception
|
||||
while (true) {
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
if ($this->a === '/') { // end pattern
|
||||
break; // while (true)
|
||||
} elseif ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
} elseif (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMin_UnterminatedRegExpException(
|
||||
'Unterminated RegExp: '. var_export($pattern, true));
|
||||
}
|
||||
$this->output .= $this->a;
|
||||
}
|
||||
$this->b = $this->next();
|
||||
}
|
||||
// end case ACTION_DELETE_A_B
|
||||
}
|
||||
}
|
||||
|
||||
protected function isRegexpLiteral()
|
||||
{
|
||||
if (false !== strpos("\n{;(,=:[!&|?", $this->a)) { // we aren't dividing
|
||||
return true;
|
||||
}
|
||||
if (' ' === $this->a) {
|
||||
$length = strlen($this->output);
|
||||
if ($length < 2) { // weird edge case
|
||||
return true;
|
||||
}
|
||||
// you can't divide a keyword
|
||||
if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
|
||||
if ($this->output === $m[0]) { // odd but could happen
|
||||
return true;
|
||||
}
|
||||
// make sure it's a keyword, not end of an identifier
|
||||
$charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
|
||||
if (! $this->isAlphaNum($charBeforeKeyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. Convert ctrl char to space.
|
||||
*/
|
||||
protected function get()
|
||||
{
|
||||
$c = $this->lookAhead;
|
||||
$this->lookAhead = null;
|
||||
if ($c === null) {
|
||||
if ($this->inputIndex < $this->inputLength) {
|
||||
$c = $this->input[$this->inputIndex];
|
||||
$this->inputIndex += 1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($c === "\r" || $c === "\n") {
|
||||
return "\n";
|
||||
}
|
||||
if (ord($c) < self::ORD_SPACE) { // control char
|
||||
return ' ';
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. If is ctrl character, translate to a space or newline.
|
||||
*/
|
||||
protected function peek()
|
||||
{
|
||||
$this->lookAhead = $this->get();
|
||||
return $this->lookAhead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII?
|
||||
*/
|
||||
protected function isAlphaNum($c)
|
||||
{
|
||||
return (preg_match('/^[0-9a-zA-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
||||
}
|
||||
|
||||
protected function singleLineComment()
|
||||
{
|
||||
$comment = '';
|
||||
while (true) {
|
||||
$get = $this->get();
|
||||
$comment .= $get;
|
||||
if (ord($get) <= self::ORD_LF) { // EOL reached
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/{$comment}";
|
||||
}
|
||||
return $get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function multipleLineComment()
|
||||
{
|
||||
$this->get();
|
||||
$comment = '';
|
||||
while (true) {
|
||||
$get = $this->get();
|
||||
if ($get === '*') {
|
||||
if ($this->peek() === '/') { // end of comment reached
|
||||
$this->get();
|
||||
// if comment preserved by YUI Compressor
|
||||
if (0 === strpos($comment, '!')) {
|
||||
return "\n/*" . substr($comment, 1) . "*/\n";
|
||||
}
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/*{$comment}*/";
|
||||
}
|
||||
return ' ';
|
||||
}
|
||||
} elseif ($get === null) {
|
||||
throw new JSMin_UnterminatedCommentException('Unterminated Comment: ' . var_export('/*' . $comment, true));
|
||||
}
|
||||
$comment .= $get;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next character, skipping over comments.
|
||||
* Some comments may be preserved.
|
||||
*/
|
||||
protected function next()
|
||||
{
|
||||
$get = $this->get();
|
||||
if ($get !== '/') {
|
||||
return $get;
|
||||
}
|
||||
switch ($this->peek()) {
|
||||
case '/': return $this->singleLineComment();
|
||||
case '*': return $this->multipleLineComment();
|
||||
default: return $get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JSMin_UnterminatedStringException extends Exception {}
|
||||
class JSMin_UnterminatedCommentException extends Exception {}
|
||||
class JSMin_UnterminatedRegExpException extends Exception {}
|
||||
@@ -85,7 +85,8 @@ class MRCreateTickets implements IMondialRelayWSMethod
|
||||
'Expe_CP' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{5}$#'),
|
||||
'params' => array(),
|
||||
'methodValidation' => 'checkZipcodeByCountry'),
|
||||
'Expe_Pays' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
@@ -129,7 +130,8 @@ class MRCreateTickets implements IMondialRelayWSMethod
|
||||
'Dest_CP' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{5}$#'),
|
||||
'params' => array(),
|
||||
'methodValidation' => 'checkZipcodeByCountry'),
|
||||
'Dest_Pays' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
@@ -277,6 +279,7 @@ class MRCreateTickets implements IMondialRelayWSMethod
|
||||
$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');
|
||||
$this->_fields['list']['Expe_CP']['params']['id_country'] = Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
|
||||
if (_PS_VERSION_ >= '1.4')
|
||||
$this->_fields['list']['Expe_Pays']['value'] = Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID'));
|
||||
@@ -332,6 +335,7 @@ class MRCreateTickets implements IMondialRelayWSMethod
|
||||
$tmp['Dest_Ad3']['value'] = $deliveriesAddress->address1;
|
||||
$tmp['Dest_Ville']['value'] = $deliveriesAddress->city;
|
||||
$tmp['Dest_CP']['value'] = $deliveriesAddress->postcode;
|
||||
$tmp['Dest_CP']['params']['id_country'] = $deliveriesAddress->id_country;
|
||||
$tmp['Dest_Pays']['value'] = $destIsoCode;
|
||||
$tmp['Dest_Tel1']['value'] = $deliveriesAddress->phone;
|
||||
$tmp['Dest_Tel2']['value'] = $deliveriesAddress->phone_mobile;
|
||||
@@ -369,9 +373,18 @@ class MRCreateTickets implements IMondialRelayWSMethod
|
||||
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))
|
||||
$valueDetailed['value'] = strtoupper(MRTools::replaceAccentedCharacters($valueDetailed['value']));
|
||||
// Call a pointer function if exist to do different test
|
||||
if (isset($valueDetailed['methodValidation']) &&
|
||||
method_exists('MRTools', $valueDetailed['methodValidation']) &&
|
||||
isset($valueDetailed['params']) &&
|
||||
MRTools::$valueDetailed['methodValidation']($valueDetailed['value'], $valueDetailed['params']))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
// Use simple Regex test given by MondialRelay
|
||||
else if (isset($valueDetailed['regexValidation']) &&
|
||||
preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
// If the key is required, we set an error, else it's skipped
|
||||
else if ((!strlen($valueDetailed['value']) && $valueDetailed['required']) || strlen($valueDetailed['value']))
|
||||
{
|
||||
if (empty($valueDetailed['value']))
|
||||
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
<?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: 7086 $
|
||||
* @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 fetch relay point - 'WSI2_RecherchePointRelais'
|
||||
*/
|
||||
class MRGetRelayPoint implements IMondialRelayWSMethod
|
||||
{
|
||||
// Params is required if you use a pointer function
|
||||
private $_fields = array(
|
||||
'list' => array(
|
||||
'Enseigne' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{2}[0-9A-Z ]{6}$#'),
|
||||
'Pays' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z]{2}$#'),
|
||||
'Ville' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[A-Z_\-\' ]{2,25}$#'),
|
||||
'CP' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'params' => array(),
|
||||
'methodValidation' => 'checkZipcodeByCountry'),
|
||||
'Taille' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(XS|S|M|L|XL|XXL|3XL)$#'),
|
||||
'Poids' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9]{1,6}$#'),
|
||||
'Action' => array(
|
||||
'required' => false,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^(REL|24R|ESP|DRI)$#'),
|
||||
'Security' => array(
|
||||
'required' => true,
|
||||
'value' => '',
|
||||
'regexValidation' => '#^[0-9A-Z]{32}$#')));
|
||||
|
||||
private $_id_address_delivery = 0;
|
||||
private $_weight = 0;
|
||||
private $_webServiceKey = '';
|
||||
private $_mondialRelay = NULL;
|
||||
private $_id_carrier = 0;
|
||||
private $_id_delivery_country = 0;
|
||||
|
||||
private $_resultList = array(
|
||||
'error' => array(),
|
||||
'success' => array());
|
||||
|
||||
private $_webserviceURL = 'http://www.mondialrelay.fr/webservice/Web_Services.asmx?WSDL';
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->_id_address_delivery = (int)($params['id_address_delivery']);
|
||||
$this->_id_carrier = (int)($params['id_carrier']);
|
||||
$this->_weight = (float)($params['weight']);
|
||||
$this->_webServiceKey = Configuration::get('MR_KEY_WEBSERVICE');
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->_mondialRelay);
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_mondialRelay = new MondialRelay();
|
||||
$address = new Address($this->_id_address_delivery);
|
||||
|
||||
if (!$address)
|
||||
throw new Exception($this->_mondialrelay->l('Customer address can\'t be found'));
|
||||
|
||||
$this->_fields['list']['Enseigne']['value'] = Configuration::get('MR_ENSEIGNE_WEBSERVICE');
|
||||
$this->_fields['list']['Poids']['value'] = Configuration::get('MR_WEIGHT_COEF') * $this->_weight;
|
||||
$this->_fields['list']['Pays']['value'] = Country::getIsoById($address->id_country);
|
||||
$this->_fields['list']['Ville']['value'] = $address->city;
|
||||
$this->_fields['list']['CP']['value'] = $address->postcode;
|
||||
$this->_fields['list']['CP']['params']['id_country'] = $address->id_country;
|
||||
|
||||
$this->_generateMD5SecurityKey();
|
||||
unset($address);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the MD5 key for each param list
|
||||
*/
|
||||
private function _generateMD5SecurityKey()
|
||||
{
|
||||
$concatenationValue = '';
|
||||
foreach($this->_fields['list'] as $paramName => &$valueDetailed)
|
||||
if ($paramName != 'Texte' && $paramName != 'Security')
|
||||
{
|
||||
$valueDetailed['value'] = strtoupper($valueDetailed['value']);
|
||||
// Call a pointer function if exist to do different test
|
||||
if (isset($valueDetailed['methodValidation']) &&
|
||||
method_exists('MRTools', $valueDetailed['methodValidation']) &&
|
||||
isset($valueDetailed['params']) &&
|
||||
MRTools::$valueDetailed['methodValidation']($valueDetailed['value'], $valueDetailed['params']))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
// Use simple Regex test given by MondialRelay
|
||||
else if (isset($valueDetailed['regexValidation']) &&
|
||||
preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches))
|
||||
$concatenationValue .= $valueDetailed['value'];
|
||||
// If the key is required, we set an error, else it's skipped
|
||||
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'];
|
||||
$this->_resultList['error'][] = $error;
|
||||
}
|
||||
}
|
||||
$concatenationValue .= $this->_webServiceKey;
|
||||
$this->_fields['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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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();
|
||||
|
||||
if ($client->fault)
|
||||
$errors[$errorTotal++] = $this->_mondialRelay->l('It seems the request isn\'t valid:').
|
||||
$result;
|
||||
|
||||
$result = $result['WSI2_RecherchePointRelaisResult'];
|
||||
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
|
||||
{
|
||||
unset($result['STAT']);
|
||||
|
||||
// Clean Content
|
||||
foreach($result as &$relayPoint)
|
||||
foreach ($relayPoint as $key => &$value)
|
||||
$value = trim($value);
|
||||
$success = $result;
|
||||
}
|
||||
$this->_resultList['error'] = $errors;
|
||||
$this->_resultList['success'] = $success;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
$params = $this->_getSimpleParamArray($this->_fields['list']);
|
||||
$result = $client->call(
|
||||
'WSI2_RecherchePointRelais',
|
||||
$params,
|
||||
'http://www.mondialrelay.fr/webservice/',
|
||||
'http://www.mondialrelay.fr/webservice/WSI2_RecherchePointRelais');
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ class MRGetTickets implements IMondialRelayWSMethod
|
||||
|
||||
private $_detailedExpeditionList = array();
|
||||
private $_webServiceKey = '';
|
||||
private $_markCode = '';
|
||||
private $_mondialRelay = NULL;
|
||||
|
||||
private $_resultList = array(
|
||||
@@ -69,7 +68,6 @@ class MRGetTickets implements IMondialRelayWSMethod
|
||||
{
|
||||
$this->_detailedExpeditionList = $params['detailedExpeditionList'];
|
||||
$this->_webServiceKey = Configuration::get('MR_KEY_WEBSERVICE');
|
||||
$this->_markCode = Configuration::get('MR_CODE_MARQUE');
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
|
||||
@@ -47,22 +47,85 @@ class MRManagement extends MondialRelay
|
||||
|
||||
}
|
||||
|
||||
public static 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);
|
||||
$query = 'SELECT `id_mr_selected`
|
||||
FROM `' . _DB_PREFIX_ . 'mr_selected`
|
||||
WHERE `id_cart` = '.(int)$this->_params['id_cart'];
|
||||
|
||||
// Update if Exist else add a new entry
|
||||
if (Db::getInstance()->getRow($query))
|
||||
{
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'mr_selected`
|
||||
SET `id_method` = '.(int)$this->_params['id_mr_method'].', ';
|
||||
if (is_array($this->_params['relayPointInfo']))
|
||||
foreach($this->_params['relayPointInfo'] as $nameKey => $value)
|
||||
$query .= '`MR_Selected_'.$nameKey.'` = "'.$value.'", ';
|
||||
else // Clean the existing relay point data
|
||||
$query .= '
|
||||
MR_Selected_Num = NULL,
|
||||
MR_Selected_LgAdr1 = NULL,
|
||||
MR_Selected_LgAdr2 = NULL,
|
||||
MR_Selected_LgAdr3 = NULL,
|
||||
MR_Selected_LgAdr4 = NULL,
|
||||
MR_Selected_CP = NULL,
|
||||
MR_Selected_Pays = NULL,
|
||||
MR_Selected_Ville = NULL, ';
|
||||
$query = rtrim($query, ', ').' WHERE `id_cart` = '.(int)$this->_params['id_cart'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'mr_selected`
|
||||
(`id_customer`, `id_method`, `id_cart`, ';
|
||||
if (is_array($this->_params['relayPointInfo']))
|
||||
foreach($this->_params['relayPointInfo'] as $nameKey => $value)
|
||||
$query .= '`MR_Selected_'.$nameKey.'`, ';
|
||||
$query = rtrim($query, ', ').') VALUES (
|
||||
'.$this->_params['id_customer'].',
|
||||
'.$this->_params['id_mr_method'].',
|
||||
'.$this->_params['id_cart'].', ';
|
||||
if (is_array($this->_params['relayPointInfo']))
|
||||
foreach($this->_params['relayPointInfo'] as $nameKey => $value)
|
||||
$query .= '"'.$value.'", ';
|
||||
$query = rtrim($query, ', ').')';
|
||||
}
|
||||
Db::getInstance()->Execute($query);
|
||||
}
|
||||
|
||||
public function uninstallDetail()
|
||||
{
|
||||
$html = '';
|
||||
|
||||
switch($this->_params['action'])
|
||||
{
|
||||
case 'showFancy':
|
||||
$html .= '
|
||||
<div id="PS_MRAskBackupContent">
|
||||
<h2>'.$this->l('Uninstalling Mondial Relay').'</h2>
|
||||
<div>
|
||||
'.$this->l('You\'re attempt to uninstall the module, do you want to remove the database').' ?
|
||||
<p id="PS_MRUninstallListSelection">
|
||||
<input type="button" id="PS_MR_BackupAction" href="javascript:void(0)" value="'.$this->l('Keep it and uninstall').'"/>
|
||||
<br />
|
||||
<input type="button" id="PS_MR_UninstallAction" href="javascript:void(0)" value="'.$this->l('Remove and uninstall').'" />
|
||||
<br />
|
||||
<input type="button" id="PS_MR_StopUninstall" href="javascript:void(0)" value="'.$this->l('Cancel').'" />
|
||||
<br />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
$this->_resultList['html'] = $html;
|
||||
break;
|
||||
case 'backupAndUninstall':
|
||||
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return $this->_resultList;
|
||||
}
|
||||
|
||||
public function DeleteHistory()
|
||||
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
<?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: 6839 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/*
|
||||
** Some tools using used in the module
|
||||
*/
|
||||
class MRTools
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static public function checkZipcodeByCountry($zipcode, $params)
|
||||
{
|
||||
$id_country = $params['id_country'];
|
||||
|
||||
$zipcodeFormat = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `zip_code_format`
|
||||
FROM `'._DB_PREFIX_.'country`
|
||||
WHERE `id_country` = '.(int)$id_country);
|
||||
|
||||
if (!$zipcodeFormat)
|
||||
return false;
|
||||
|
||||
$regxMask = str_replace(
|
||||
array('N', 'C', 'L'),
|
||||
array(
|
||||
'[0-9]',
|
||||
Country::getIsoById((int)$id_country),
|
||||
'[a-zA-Z]'),
|
||||
$zipcodeFormat);
|
||||
if (preg_match('/'.$regxMask.'/', $zipcode))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user