2016-05-09 17:43:57 +02:00
< ? php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from Common - Services Co . , Ltd .
* Use , copy , modification or distribution of this source file without written
* license agreement from the SARL SMC is strictly forbidden .
* In order to obtain a license , please contact us : contact @ common - services . com
* ...........................................................................
* INFORMATION SUR LA LICENCE D ' UTILISATION
*
* L ' utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe Common - Services Co . , Ltd .
* Toute utilisation , reproduction , modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la Common - Services Co . Ltd . est
* expressement interdite .
* Pour obtenir une licence , veuillez contacter Common - Services Co . , Ltd . a l ' adresse : contact @ common - services . com
* ...........................................................................
*
* @ package So Colissimo Flexibilite
* @ author Alexandre D .
* @ copyright Copyright ( c ) 2011 - 2015 Common Services Co Ltd - 90 / 25 Sukhumvit 81 - 10260 Bangkok - Thailand
* @ license Commercial license
* Support by mail : support . soflexibilite @ common - services . com
*/
require_once ( _PS_MODULE_DIR_ . 'soflexibilite/classes/SoFlexibiliteDelivery.php' );
require_once ( _PS_MODULE_DIR_ . 'soflexibilite/classes/SoFlexibiliteTools.php' );
if ( ! class_exists ( 'ConfigureMessage' )) {
require_once ( _PS_MODULE_DIR_ . 'soflexibilite/shared/classes/configure_message.class.php' );
}
if ( ! defined ( '_PS_VERSION_' )) {
exit ;
}
class soflexibilite extends CarrierModule
{
public $id_carrier ;
protected $id_carrier_so = null ;
protected $id_carrier_so_keys = null ;
protected $soflexibilite_conf_key = array (
'SOFLEXIBILITE_DOM_ID' ,
'SOFLEXIBILITE_DOS_ID' ,
'SOFLEXIBILITE_BPR_ID' ,
'SOFLEXIBILITE_CIT_ID' ,
);
public $personal_data_phone_error = false ;
public $personal_data_zip_code_error = false ;
public $siret_error = false ;
public $ps15x ;
public $ps16x ;
public $available_country = array ( 'FR' , 'BE' , 'NL' , 'DE' , 'GB' , 'LU' , 'ES' );
public $url ;
const ADD = 'a' ;
const REMOVE = 'd' ;
const UPDATE = 'u' ;
const DEFAULT_THEME = '16' ;
const TEXT_DOM = 'Colissimo Domicile - sans signature' ;
const TEXT_DOS = 'Colissimo Domicile - avec signature' ;
const TEXT_BPR = 'Colissimo - En bureau de Poste' ;
const TEXT_A2P = 'Colissimo - En relais PickUp ou en consigne PickUp Station' ;
const INSURRANCE_STEP_DEFAULT = 150 ;
const INSURRANCE_PRICE_DEFAULT = 0.9 ;
/* Home Delivery Modes */
const HOME_DELIVERY_DOM = 'DOM' ;
const HOME_DELIVERY_DOS = 'DOS' ;
const HOME_DELIVERY_RDV = 'RDV' ;
/* Data Handling Mode */
const MODE_EXPEDITOR_PRESTASHOP = 1 ;
const MODE_EXPEDITOR_THIRDPARTY = 2 ;
public static $home_delivery_mode = self :: HOME_DELIVERY_DOM ;
public static $mode = self :: MODE_EXPEDITOR_PRESTASHOP ;
public function __construct ()
{
$this -> name = 'soflexibilite' ;
$this -> tab = 'shipping_logistics' ;
$this -> version = '3.1.05' ;
$this -> author = 'Common-Services' ;
$this -> limited_countries = array ( 'fr' );
$this -> protocol = Configuration :: get ( 'PS_SSL_ENABLED' ) ? 'https://' : 'http://' ;
$this -> url = $this -> protocol . htmlspecialchars ( $_SERVER [ 'HTTP_HOST' ], ENT_COMPAT , 'UTF-8' ) .
__PS_BASE_URI__ . 'modules/' . $this -> name ;
$this -> point_list_url = $this -> url . '/functions/point_list.php' ;
$this -> saveDelivery_url = $this -> url . '/functions/saveDeliveryPoint.php' ;
$this -> saveInfoCommande = $this -> url . '/functions/saveInfoCommande.php' ;
$this -> initSoflexibiliteEnv_url = $this -> url . '/functions/initSoflexibiliteEnv.php' ;
$this -> getCustomerAddress = $this -> url . '/functions/getCustomerAddress.php' ;
$this -> bootstrap = true ;
parent :: __construct ();
$this -> displayName = $this -> l ( 'So Colissimo Flexibilite - Officiel' );
$this -> description = $this -> l ( 'So Colissimo is a service from La Poste which allow you to suggest 5 carrier mode to your customers.' );
$this -> confirmUninstall = $this -> l ( 'Do you really want to uninstall this module ?' );
// 1 - Set the data handling mode
self :: $mode = (( int ) Configuration :: get ( 'SOFLEXIBILITE_MODE' ) == self :: MODE_EXPEDITOR_THIRDPARTY ) ?
self :: MODE_EXPEDITOR_THIRDPARTY : self :: MODE_EXPEDITOR_PRESTASHOP ;
// DOM or DOS - Home delivery with or without signature
if (( $home_delivery_mode = Configuration :: get ( 'SOFLEXIBILITE_HOME_MODE' ))) {
self :: $home_delivery_mode = $home_delivery_mode ;
}
$this -> _mapIdentifiers ();
// Configuration par defaut des transporteurs
$this -> config = array (
'name' => '' ,
'id_tax' => 1 ,
'id_tax_rules_group' => 1 ,
'url' => 'http://www.colissimo.fr/portail_colissimo/suivreResultat.do?parcelnumber=@' ,
'active' => true ,
'deleted' => 0 ,
'shipping_handling' => false ,
'range_behavior' => 0 ,
'is_module' => false ,
'id_zone' => 1 ,
'shipping_external' => true ,
'external_module_name' => 'soflexibilite' ,
'need_range' => true
);
$this -> _initContext ();
}
/* Retrocompatibility 1.4/1.5 */
private function _initContext ()
{
$this -> ps16x = false ;
if ( version_compare ( _PS_VERSION_ , '1.6' , '>=' )) {
$this -> ps16x = true ;
}
if ( version_compare ( _PS_VERSION_ , '1.5' , '>=' )) {
$this -> context = Context :: getContext ();
$this -> id_lang = ( int ) Context :: getContext () -> language -> id ;
$this -> ps15x = true ;
} else {
require_once ( _PS_MODULE_DIR_ . $this -> name . '/backward_compatibility/backward.php' );
$this -> context = Context :: getContext ();
$this -> id_lang = ( int ) Context :: getContext () -> language -> id ;
$this -> ps15x = false ;
$this -> local_path = _PS_MODULE_DIR_ . $this -> name . '/' ;
}
}
private function _mapIdentifiers ()
{
$this -> soflexibilite_conf_key = array ( 'SOFLEXIBILITE_DOM_ID' , 'SOFLEXIBILITE_DOS_ID' , 'SOFLEXIBILITE_RDV_ID' , 'SOFLEXIBILITE_BPR_ID' , 'SOFLEXIBILITE_A2P_ID' , 'SOFLEXIBILITE_CIT_ID' );
$this -> id_carrier_so = Configuration :: getMultiple ( $this -> soflexibilite_conf_key , null , null , null );
if ( is_array ( $this -> id_carrier_so )) {
$this -> id_carrier_so_keys = @ array_flip ( $this -> id_carrier_so );
} else {
$this -> id_carrier_so_keys = array ();
$this -> id_carrier_so = array ();
}
}
private function _autoInstall ( $state )
{
$pass = true ;
if ( ! $this -> createSoColissimo ( 'DOM' , html_entity_decode ( self :: TEXT_DOM , ENT_COMPAT , 'UTF-8' ), $state )) {
$this -> _errors [] = $this -> l ( 'An error occured while creating carrier : mon domicile (sans signature).' );
$pass = false ;
}
if ( ! $this -> createSoColissimo ( 'DOS' , html_entity_decode ( self :: TEXT_DOS , ENT_COMPAT , 'UTF-8' ), $state )) {
$this -> _errors [] = $this -> l ( 'An error occured while creating carrier : mon domicile (avec signautre).' );
$pass = false ;
}
if ( ! $this -> createSoColissimo ( 'BPR' , html_entity_decode ( self :: TEXT_BPR , ENT_COMPAT , 'UTF-8' ), $state )) {
$this -> _errors [] = $this -> l ( 'An error occured while creating carrier : mon bureau de poste.' );
$pass = false ;
}
if ( ! $this -> createSoColissimo ( 'A2P' , html_entity_decode ( self :: TEXT_A2P , ENT_COMPAT , 'UTF-8' ), $state )) {
$this -> _errors [] = $this -> l ( 'An error occured while creating carrier : mon commercant.' );
$pass = false ;
}
if ( ! ( int ) Configuration :: get ( 'SOFLEXIBILITE_DOM_ID' )) {
$this -> _removePreviousVersion ();
}
$this -> _mapIdentifiers ();
if ( ! $this -> _hookSetup ( SoFlexibilite :: ADD )) {
$this -> _errors [] = $this -> l ( 'An error occured while registering hooks.' );
$pass = false ;
}
return ( $pass );
}
private function _removePreviousVersion ()
{
$table = 'carrier' ;
$values = array (
'deleted' => ( int ) 1
);
$where = '`external_module_name` = "soflexibilite" ' ;
if (( $rows = Db :: getInstance () -> executeS ( 'SELECT `id_carrier` FROM ' . _DB_PREFIX_ . 'carrier WHERE ' . $where ))) {
foreach ( $rows as $carrier_row ) {
if ( ! in_array ( $carrier_row [ 'id_carrier' ], $this -> id_carrier_so )) {
if ( $this -> ps15x ) {
Db :: getInstance () -> update ( $table , $values , $where . ' AND `id_carrier` = ' . ( int ) $carrier_row [ 'id_carrier' ]);
} else {
Db :: getInstance () -> autoExecute ( $table , $values , 'UPDATE' , $where );
}
}
}
}
}
public function install ()
{
$pass = true ;
if ( ! parent :: install ()) {
$this -> _errors [] = $this -> l ( 'An error occured while installing with parent::install().' );
$pass = false ;
}
$this -> _removePreviousVersion ();
$this -> _autoInstall ( true );
$sql = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . ' socolissimo_delivery_info ` (
`id_cart` INT ( 10 ) NOT NULL ,
`id_customer` INT ( 10 ) NOT NULL ,
`delivery_mode` VARCHAR ( 3 ) NOT NULL ,
`prid` TEXT ( 10 ) NOT NULL ,
`prname` VARCHAR ( 64 ) NOT NULL ,
`prfirstname` VARCHAR ( 64 ) NOT NULL ,
`prcompladress` TEXT NOT NULL ,
`pradress1` TEXT NOT NULL ,
`pradress2` TEXT NOT NULL ,
`pradress3` TEXT NOT NULL ,
`pradress4` TEXT NOT NULL ,
`przipcode` TEXT ( 10 ) NOT NULL ,
`prtown` VARCHAR ( 64 ) NOT NULL ,
`cecountry` VARCHAR ( 10 ) NOT NULL ,
`cephonenumber` VARCHAR ( 15 ) NOT NULL ,
`ceemail` VARCHAR ( 64 ) NOT NULL ,
`cecompanyname` VARCHAR ( 64 ) NOT NULL ,
`cedeliveryinformation` TEXT NOT NULL ,
`cedoorcode1` VARCHAR ( 10 ) NOT NULL ,
`cedoorcode2` VARCHAR ( 10 ) NOT NULL ,
`codereseau` VARCHAR ( 3 ) DEFAULT NULL ,
PRIMARY KEY ( `id_cart` , `id_customer` )
) ENGINE = InnoDB DEFAULT CHARSET = utf8 ; ' ;
if ( ! Db :: getInstance () -> Execute ( $sql )) {
$pass = false ;
}
Configuration :: updateValue ( 'SOFLEXIBILITE_MODE' , 1 );
Configuration :: updateValue ( 'SOFLEXIBILITE_THEME' , self :: DEFAULT_THEME );
Configuration :: updateValue ( 'SOFLEXIBILITE_GMAP' , 1 );
Configuration :: updateValue ( 'SOFLEXIBILITE_WS' , 'https://ws.colissimo.fr/pointretrait-ws-cxf/PointRetraitServiceWS/2.0?wsdl' );
Configuration :: updateValue ( 'SOFLEXIBILITE_LOGIN' , '' );
Configuration :: updateValue ( 'SOFLEXIBILITE_PASSWORD' , '' );
Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE' , false );
Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE_PRICE' , ( float ) 0.9 );
Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE_STEP' , 150 );
Configuration :: updateValue ( 'SOFLEXIBILITE_SUB_PHONE' , str_replace ( ' ' , '' , ( string ) Configuration :: get ( 'PS_SHOP_PHONE' )));
Configuration :: updateValue ( 'SOFLEXIBILITE_ONLY_MAP' , false );
ConfigureMessage :: display ();
return (( bool ) $pass );
}
public function uninstall ()
{
$pass = true ;
if ( ! parent :: uninstall ()) {
$this -> _errors [] = $this -> l ( 'An error occured while uninstalling with parent::uninstall().' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_DOM_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon domicile.' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_DOS_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon domicile.' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_RDV_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon rendez-vous.' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_BPR_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon bureau de poste.' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_A2P_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon commercant.' );
$pass = false ;
}
if ( ! Db :: getInstance () -> execute ( 'UPDATE ' . _DB_PREFIX_ . 'carrier SET deleted=1 WHERE id_carrier=' . ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_CIT_ID' ])) {
$this -> _errors [] = $this -> l ( 'An error occured while udating mon cityssimo.' );
$pass = false ;
}
if ( ! $this -> _hookSetup ( SoFlexibilite :: REMOVE )) {
$this -> _errors [] = $this -> l ( 'An error occured while unregistering hooks.' );
$pass = false ;
}
Configuration :: deleteByName ( 'SOFLEXIBILITE_DOM_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_DOS_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_RDV_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_BPR_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_A2P_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_CIT_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_DOM' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_DOS' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_RDV' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_BPR' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_A2P' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_CIT' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_DOM' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_DOS' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_RDV' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_BPR' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_A2P' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_CIT' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_DOM_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_DOS_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_RDV_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_BPR_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_A2P_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ASSOCIATE_CIT_ID' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_THEME' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_GMAP' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_MODE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_HOME_MODE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_WS' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_LOGIN' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_PASSWORD' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_INSURRANCE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_INSURRANCE_PRICE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_INSURRANCE_STEP' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_USER_HOME_MODE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_FORCE_DOS' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_FORCE_DOS_VALUE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_SUB_PHONE' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_ONLY_MAP' );
Configuration :: deleteByName ( 'SOFLEXIBILITE_MAP_STYLE' );
return (( bool ) $pass );
}
public static function isDirWriteable ( $path )
{
$path = rtrim ( $path , '/\\' );
$testfile = sprintf ( '%s%stestfile_%s.chk' , $path , DIRECTORY_SEPARATOR , uniqid ());
$timestamp = time ();
if ( @ file_put_contents ( $testfile , $timestamp )) {
$result = trim ( @ SoFlexibiliteTools :: file_get_contents ( $testfile ));
@ unlink ( $testfile );
if (( int ) $result == ( int ) $timestamp ) {
return ( true );
}
}
return ( false );
}
private function createSoColissimo ( $mode , $str , $state )
{
foreach ( $this -> id_carrier_so as $configuration_key => $id_carrier ) {
// Not the target carrier
if ( $configuration_key != 'SOFLEXIBILITE_' . $mode . '_ID' ) {
continue ;
}
// Not Yet Configured
if ( $id_carrier === false ) {
break ;
}
$carrier = new Carrier ( $id_carrier );
if ( Validate :: isLoadedObject ( $carrier )) {
if ( $carrier -> deleted ) {
break ;
}
// Already active
return ( true );
}
}
$carrier = new Carrier ();
foreach ( $this -> config as $k => $v ) {
$carrier -> { $k } = $v ;
}
$carrier -> { 'name' } .= $str ;
$carrier -> { 'active' } = ( int ) $state ;
foreach ( Language :: getLanguages ( false ) as $language ) {
if ( $language [ 'iso_code' ] == 'fr' ) {
if ( $mode === 'DOM' || $mode === 'DOS' ) {
$carrier -> delay [ $language [ 'id_lang' ]] = 'Faites vous livrer à l\'adresse de votre choix, ' . ( $mode === 'DOM' ? 'sans' : 'avec' ) . ' signature' ;
} elseif ( $mode === 'BPR' ) {
$carrier -> delay [ $language [ 'id_lang' ]] = 'Faites vous livrer dans l\'un des bureaux de poste parmi 10 000 points de retrait partout en France' ;
} elseif ( $mode === 'A2P' ) {
$carrier -> delay [ $language [ 'id_lang' ]] = 'Faites vous livrer dans l\'un des relais pickup ou consignes Pickup Station parmi 8 000 points de retrait partout en France' ;
} else {
$carrier -> delay [ $language [ 'id_lang' ]] = 'Faites vous livrer en France selon votre choix.' ;
}
} else {
$carrier -> delay [ $language [ 'id_lang' ]] = 'Get delivered at home, in France.' ;
}
}
if ( $carrier -> add ()) {
if ( $this -> ps15x && Feature :: isFeatureActive ()) {
Configuration :: updateGlobalValue ( 'SOFLEXIBILITE_' . $mode . '_ID' , ( int ) $carrier -> id , false );
} else {
Configuration :: updateValue ( 'SOFLEXIBILITE_' . $mode . '_ID' , ( int ) $carrier -> id );
}
$groups = Group :: getGroups (( int ) $this -> id_lang );
foreach ( $groups as $group ) {
$table = 'carrier_group' ;
$values = array (
'id_carrier' => ( int ) $carrier -> id ,
'id_group' => ( int ) $group [ 'id_group' ]
);
if ( $this -> ps15x ) {
Db :: getInstance () -> insert ( $table , $values );
} else {
Db :: getInstance () -> autoExecute ( _DB_PREFIX_ . $table , $values , 'INSERT' );
}
}
$rangePrice = new RangePrice ();
$rangePrice -> id_carrier = $carrier -> id ;
$rangePrice -> delimiter1 = 0 ;
$rangePrice -> delimiter2 = 10000 ;
$rangePrice -> add ();
$rangeWeight = new RangeWeight ();
$rangeWeight -> id_carrier = $carrier -> id ;
$rangeWeight -> delimiter1 = 0 ;
$rangeWeight -> delimiter2 = 10000 ;
$rangeWeight -> add ();
$zones = Zone :: getZones ( true );
foreach ( $zones as $zone ) {
$carrier -> addZone (( int ) $zone [ 'id_zone' ]);
}
// copie du logo
if ( ! self :: isDirWriteable ( dirname ( __FILE__ ) . '/img/' )) {
$this -> _errors [] = printf ( 'Fatal Error - %s: %d - %s.' , __FILE__ , __LINE__ , $this -> l ( 'The image directory is not writable' ));
return ( false );
} else {
$img_path = null ;
switch ( $mode ) {
case 'DOM' :
case 'DOS' :
case 'BPR' :
case 'A2P' :
$img_path = dirname ( __FILE__ ) . '/img/colissimo_carrier_logo.png' ;
break ;
}
$pass = true ;
if ( ! $img_path ) {
$pass = false ;
} elseif ( method_exists ( 'Tools' , 'copy' ) && ! Tools :: copy ( $img_path , _PS_SHIP_IMG_DIR_ . '/' . $carrier -> id . '.jpg' )) {
$pass = false ;
} elseif ( ! method_exists ( 'Tools' , 'copy' ) && ! SoFlexibiliteTools :: copy ( $img_path , _PS_SHIP_IMG_DIR_ . '/' . $carrier -> id . '.jpg' )) {
$pass = false ;
}
if ( ! $pass ) {
$this -> _errors [] = printf ( 'Fatal Error - %s: %d - %s (%d) %s.' , __FILE__ , __LINE__ , $this -> l ( 'Impossible to copy image for carrier' ), $carrier -> id , $carrier -> name );
return ( false );
}
}
} else {
$this -> _errors [] = printf ( 'Fatal Error - %s: %d - %s (%s).' , __FILE__ , __LINE__ , $this -> l ( 'Impossible to create carrier.' ), $mode );
return ( false );
}
return ( true );
}
public function getContent ()
{
$output = null ;
$expeditor_conf = Configuration :: getMultiple ( array (
'EXPEDITOR_CARRIER_CODES_' . $this -> id_carrier_so [ 'SOFLEXIBILITE_DOM_ID' ],
'EXPEDITOR_CARRIER_CODES_' . $this -> id_carrier_so [ 'SOFLEXIBILITE_DOS_ID' ],
'EXPEDITOR_CARRIER_CODES_' . $this -> id_carrier_so [ 'SOFLEXIBILITE_BPR_ID' ],
'EXPEDITOR_CARRIER_CODES_' . $this -> id_carrier_so [ 'SOFLEXIBILITE_A2P_ID' ],
));
if ( Module :: isInstalled ( 'expeditor' )) {
foreach ( $expeditor_conf as $exp_carrier_conf => $val ) {
if ( $val !== 'SO' ) {
Configuration :: updateValue ( $exp_carrier_conf , 'SO' );
$output .= $this -> displayConfirmation ( 'Une erreur avec le module Expeditor Inet a été corrigé (' . $exp_carrier_conf . ').' );
}
}
}
$this -> _removePreviousVersion ();
if ( version_compare ( _PS_VERSION_ , '1.4.4.0' , '>=' )) {
$this -> _autoInstall ( false );
}
// Bug Fix with Prestashop form management
$real_submit = ( bool ) Tools :: getValue ( 'SOFLEXIBILITE_LOGIN' );
if ( Tools :: isSubmit ( 'submit' . $this -> name ) && $real_submit ) {
$success = true ;
$compat_type = Tools :: getValue ( 'SOFLEXIBILITE_MODE' , 1 );
// Theme
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_ONLY_MAP' , Tools :: getValue ( 'SOFLEXIBILITE_ONLY_MAP' , false ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_THEME' , Tools :: getValue ( 'SOFLEXIBILITE_THEME' , self :: DEFAULT_THEME ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_MAP_STYLE' , Tools :: getValue ( 'SOFLEXIBILITE_MAP_STYLE' ));
// Compatibility mode
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_MODE' , Tools :: getValue ( 'SOFLEXIBILITE_MODE' , 1 ));
// Insurrance
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE' , ( int ) Tools :: getValue ( 'SOFLEXIBILITE_INSURRANCE' , false ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE_PRICE' , ( float ) Tools :: getValue ( 'SOFLEXIBILITE_INSURRANCE_PRICE' , self :: INSURRANCE_PRICE_DEFAULT ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_INSURRANCE_STEP' , ( float ) Tools :: getValue ( 'SOFLEXIBILITE_INSURRANCE_STEP' , self :: INSURRANCE_STEP_DEFAULT ));
// Sub phone
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_SUB_PHONE' , ( string ) Tools :: getValue ( 'SOFLEXIBILITE_SUB_PHONE' , false ));
if ( Tools :: getValue ( 'SOFLEXIBILITE_SUB_PHONE' ) && ! preg_match ( '/^0[67](\s?\d{2}){4}$/i' , Tools :: getValue ( 'SOFLEXIBILITE_SUB_PHONE' , false ))) {
ConfigureMessage :: error ( $this -> l ( 'Your substitution phone number do not have the required format.' ));
}
// Login and password check
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_LOGIN' , Tools :: getValue ( 'SOFLEXIBILITE_LOGIN' ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_PASSWORD' , Tools :: getValue ( 'SOFLEXIBILITE_PASSWORD' ));
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_WS' , Tools :: getValue ( 'SOFLEXIBILITE_WS' ));
// Enable Google Map
$success &= Configuration :: updateValue ( 'SOFLEXIBILITE_GMAP' , Tools :: getValue ( 'SOFLEXIBILITE_GMAP' , 1 ));
$tables = array ();
$query = Db :: getInstance () -> executeS ( 'SHOW TABLES' );
foreach ( $query as $rows ) {
foreach ( $rows as $table ) {
$tables [ $table ] = 1 ;
}
}
SoFlexibiliteTools :: checkTables ( $compat_type , $tables );
$fields = array ();
if ( $compat_type == 1 && isset ( $tables [ _DB_PREFIX_ . 'socolissimo_delivery_info' ])) {
$query = Db :: getInstance () -> ExecuteS ( 'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'socolissimo_delivery_info`' );
foreach ( $query as $row ) {
$fields [ $row [ 'Field' ]] = 1 ;
}
if ( ! isset ( $fields [ 'codereseau' ])) {
$sql = 'ALTER TABLE `' . _DB_PREFIX_ . 'socolissimo_delivery_info` ADD `codereseau` VARCHAR(3) DEFAULT NULL' ;
if ( ! Db :: getInstance () -> execute ( $sql )) {
ConfigureMessage :: error ( $this -> l ( 'Error while updating table `socolissimo_delivery_info`.' ));
} else {
ConfigureMessage :: success ( $this -> l ( 'Field `codereseau` added to the table `socolissimo_delivery_info`.' ));
}
}
} elseif ( $compat_type == 2 && isset ( $tables [ _DB_PREFIX_ . 'so_delivery' ])) {
$query = Db :: getInstance () -> ExecuteS ( 'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'so_delivery`' );
foreach ( $query as $row ) {
$fields [ $row [ 'Field' ]] = 1 ;
}
if ( ! isset ( $fields [ 'codereseau' ])) {
$sql = 'ALTER TABLE `' . _DB_PREFIX_ . 'so_delivery` ADD `codereseau` VARCHAR(3) DEFAULT NULL' ;
if ( ! Db :: getInstance () -> execute ( $sql )) {
ConfigureMessage :: error ( $this -> l ( 'Error while updating table `so_delivery`.' ));
} else {
ConfigureMessage :: success ( $this -> l ( 'Field `codereseau` added to the table `so_delivery`.' ));
}
}
}
if ( $success ) {
ConfigureMessage :: success ( $this -> l ( 'Options updated.' ));
} else {
ConfigureMessage :: error ( $this -> l ( 'An error occurred.' ));
}
}
if ( ! empty ( $_POST ) && ( Tools :: isSubmit ( 'submitPersonalSave' ) || Tools :: isSubmit ( 'submitPersonalCancel' ))) {
$validation = $this -> postPersonalProcess ();
} else {
$validation = true ;
}
if ( ! Configuration :: get ( 'SOCOLISSIMO_PERSONAL_DATA' )) {
$output .= $this -> displayPersonalDataForm ( $validation );
}
return $output . $this -> displayForm ();
}
protected function displayPersonalDataForm ( $validation = false )
{
$referer = isset ( $_SERVER [ 'HTTP_REFERER' ]) ? $_SERVER [ 'HTTP_REFERER' ] : false ;
if (( ! $referer || ( $referer && strpos ( $referer , 'configure' ))) && ( $validation == true )) {
return false ;
}
$phone = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_PHONE' );
$zip_code = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_ZIP_CODE' );
$shop_zip_code = Configuration :: get ( 'PS_SHOP_CODE' );
$shop_phone = Configuration :: get ( 'PS_SHOP_PHONE' );
$parcels = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_QUANTITIES' );
$siret = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_SIRET' );
$module_dir = _MODULE_DIR_ . $this -> name ;
$this -> context -> smarty -> assign ( array (
'moduleDir' => $module_dir ,
'siret' => $siret ,
'parcels' => $parcels ,
'phone' => $phone ,
'zip_code' => $zip_code ,
'shop_zip_code' => $shop_zip_code ,
'shop_phone' => $shop_phone ,
'personal_data_phone_error' => $this -> personal_data_phone_error ,
'personal_data_zip_code_error' => $this -> personal_data_zip_code_error ,
'siret_error' => $this -> siret_error
));
return ( $this -> context -> smarty -> fetch ( dirname ( __FILE__ ) . '/views/templates/admin/personnal_data.tpl' ));
}
protected function postPersonalProcess ()
{
if ( Tools :: isSubmit ( 'submitPersonalSave' )) {
$phone = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_PHONE' );
$zip_code = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_ZIP_CODE' );
$quantities = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_QUANTITIES' );
$siret = Tools :: getValue ( 'SOCOLISSIMO_PERSONAL_SIRET' );
$this -> personal_data_phone_error = false ;
$this -> personal_data_zip_code_error = false ;
$this -> siret_error = false ;
if ( ! ( bool ) preg_match ( '#^(([\d]{2})([\s]){0,1}){5}$#' , $phone )) {
$this -> personal_data_phone_error = true ;
return ( false );
}
if ( ! ( bool ) preg_match ( '#^(([0-8][0-9])|(9[0-5]))[0-9]{3}$#' , $zip_code )) {
$this -> personal_data_zip_code_error = true ;
return ( false );
}
if ( ! $siret ) {
$this -> siret_error = true ;
return ( false );
}
Configuration :: updateValue ( 'SOCOLISSIMO_PERSONAL_PHONE' , $phone );
Configuration :: updateValue ( 'SOCOLISSIMO_PERSONAL_ZIP_CODE' , $zip_code );
Configuration :: updateValue ( 'SOCOLISSIMO_PERSONAL_QUANTITIES' , $quantities );
Configuration :: updateValue ( 'SOCOLISSIMO_PERSONAL_SIRET' , $siret );
$this -> savePreactivationRequest ();
}
if ( Tools :: isSubmit ( 'submitPersonalSave' ) || Tools :: isSubmit ( 'submitPersonalCancel' )) {
Configuration :: updateValue ( 'SOCOLISSIMO_PERSONAL_DATA' , true );
}
return ( true );
}
protected function savePreactivationRequest ()
{
return ;
/* if ( version_compare ( _PS_VERSION_ , '1.5' , '<' )) {
return ( $this -> savePreactivationRequest14 ());
}
return ( $this -> savePreactivationRequest15 ()); */
}
protected function savePreactivationRequest14 ()
{
return ;
/* $employee = new Employee (( int ) Context :: getContext () -> cookie -> id_employee );
$data = array (
'version' => '1.0' ,
'partner' => $this -> name ,
'country_iso_code' => Tools :: strtoupper ( Country :: getIsoById ( Configuration :: get ( 'PS_COUNTRY_DEFAULT' ))),
'security' => md5 ( $employee -> email . _COOKIE_IV_ ),
'partner' => $this -> name ,
'email' => $employee -> email ,
'firstName' => $employee -> firstname ,
'lastName' => $employee -> lastname ,
'shop' => Configuration :: get ( 'PS_SHOP_NAME' ),
'host' => $_SERVER [ 'HTTP_HOST' ],
'phoneNumber' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_PHONE' ),
'postalCode' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_ZIP_CODE' ),
'businessType' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_QUANTITIES' ),
'siret' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_SIRET' ),
);
$query = http_build_query ( $data );
return ( @ SoFlexibiliteTools :: file_get_contents ( 'http://api.prestashop.com/partner/preactivation/actions.php?' . $query )); */
}
protected function savePreactivationRequest15 ()
{
return ;
$employee = new Employee (( int ) Context :: getContext () -> cookie -> id_employee );
/* $data = array (
'iso_lang' => Tools :: strtolower ( $this -> context -> language -> iso_code ),
'iso_country' => Tools :: strtoupper ( $this -> context -> country -> iso_code ),
'host' => $_SERVER [ 'HTTP_HOST' ],
'ps_version' => _PS_VERSION_ ,
'ps_creation' => _PS_CREATION_DATE_ ,
'partner' => $this -> name ,
'firstname' => $employee -> firstname ,
'lastname' => $employee -> lastname ,
'email' => $employee -> email ,
'shop' => Configuration :: get ( 'PS_SHOP_NAME' ),
'type' => 'home' ,
'phone' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_PHONE' ),
'zipcode' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_ZIP_CODE' ),
'fields' => serialize (
array (
'quantities' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_QUANTITIES' ),
'siret' => Configuration :: get ( 'SOCOLISSIMO_PERSONAL_SIRET' ),
)
),
);
$query = http_build_query ( $data );
return ( @ SoFlexibiliteTools :: file_get_contents ( 'http://api.prestashop.com/partner/premium/set_request.php?' . $query )); */
}
public function toMegaBytes ( $memsize )
{
$unit = Tools :: strtolower ( Tools :: substr ( $memsize , - 1 ));
$val = preg_replace ( '[^0-9]' , '' , $memsize );
switch ( $unit ) {
case 'g' :
$val = $val * 1024 * 1024 * 1024 ;
break ;
case 'm' :
$val = $val * 1024 * 1024 ;
break ;
case 'k' :
$val = $val * 1024 ;
break ;
default :
$val = false ;
}
// Switch to MB
$memsize = $val / ( 1024 * 1024 );
return ( $memsize );
}
private function _atLeastOneOutIsActive ()
{
$bpr_carrier = new Carrier ( Configuration :: get ( 'SOFLEXIBILITE_BPR_ID' ));
if ( Validate :: isLoadedObject ( $bpr_carrier ) && $bpr_carrier -> active ) {
return ( true );
}
$a2p_carrier = new Carrier ( Configuration :: get ( 'SOFLEXIBILITE_A2P_ID' ));
if ( Validate :: isLoadedObject ( $a2p_carrier ) && $a2p_carrier -> active ) {
return ( true );
}
$cit_carrier = new Carrier ( Configuration :: get ( 'SOFLEXIBILITE_CIT_ID' ));
if ( Validate :: isLoadedObject ( $cit_carrier ) && $cit_carrier -> active ) {
return ( true );
}
return ( false );
}
private function _backofficeInformations ()
{
$php_infos = array ();
$module_infos = array ();
$prestashop_infos = array ();
// WEB SERVICE SETTINGS
if ( Configuration :: get ( 'SOFLEXIBILITE_WS' ) == '' ) {
$module_infos [ 'web_service' ][ 'message' ] = sprintf ( $this -> l ( 'The web service URL is empty, please fill it with a valid link to the ColiPoste web service.' ));
$module_infos [ 'web_service' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
}
if (( Configuration :: get ( 'SOFLEXIBILITE_LOGIN' )) == '' ) {
$module_infos [ 'ws_login' ][ 'message' ] = sprintf ( $this -> l ( 'You did not set a login yet, please fill the login field in the Configuration tab.' ));
$module_infos [ 'ws_login' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
}
if (( Configuration :: get ( 'SOFLEXIBILITE_PASSWORD' )) == '' ) {
$module_infos [ 'ws_pwd' ][ 'message' ] = sprintf ( $this -> l ( 'You did not set a password yet, please fill the password field in the Configuration tab.' ));
$module_infos [ 'ws_pwd' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
}
$dom_carrier = new Carrier ( Configuration :: get ( 'SOFLEXIBILITE_DOM_ID' ));
$dos_carrier = new Carrier ( Configuration :: get ( 'SOFLEXIBILITE_DOS_ID' ));
if ( ! Validate :: isLoadedObject ( $dom_carrier ) || ! Validate :: isLoadedObject ( $dos_carrier ) || ! max ( 0 , ( int ) $dom_carrier -> active , ( int ) $dos_carrier -> active )) {
$module_infos [ 'coliposte' ][ 'message' ] = sprintf ( $this -> l ( 'You have to activate the home carrier with at least one out of home carrier, this is a contract condition with coliposte.' ));
$module_infos [ 'coliposte' ][ 'level' ] = $this -> ps16x ? 'alert alert-danger' : 'error' ;
} else {
if ( ! $this -> _atLeastOneOutIsActive ()) {
$module_infos [ 'coliposte' ][ 'message' ] = sprintf ( $this -> l ( 'You have to activate the home carrier with at least one out of home carrier, this is a contract condition with coliposte.' ));
$module_infos [ 'coliposte' ][ 'level' ] = $this -> ps16x ? 'alert alert-danger' : 'error' ;
}
}
// PHP Configuration Check
/* if (( $max_execution_time = ini_get ( 'max_execution_time' )) && $max_execution_time > - 1 && $max_execution_time < 60 ) {
$php_infos [ 'max_execution_time' ][ 'message' ] = sprintf ( $this -> l ( 'PHP value: max_execution_time recommended value is at least 60. your limit is currently set to %d' ), $max_execution_time );
$php_infos [ 'max_execution_time' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
} */
if ( ! class_exists ( 'SoapClient' )) {
$php_infos [ 'soap_client' ][ 'message' ] = $this -> l ( 'Soap Client Extension must be active for running this extension' );
$php_infos [ 'soap_client' ][ 'level' ] = $this -> ps16x ? 'alert alert-danger' : 'error' ;
$php_infos [ 'soap_client' ][ 'link' ] = 'http://php.net/manual/' . $this -> context -> language -> iso_code . '/soap.setup.php' ;
}
if ( in_array ( @ Tools :: strtolower ( ini_get ( 'display_errors' )), array ( '1' , 'on' ))) {
$php_infos [ 'display_errors' ][ 'message' ] = $this -> l ( 'PHP variable display_errors is On.' );
$php_infos [ 'display_errors' ][ 'level' ] = $this -> ps16x ? 'alert alert-info' : ( version_compare ( _PS_VERSION_ , '1.5' , '<' ) ? 'hint' : 'info' );
}
// Memory Limit
$memory_limit = $this -> toMegaBytes ( ini_get ( 'memory_limit' ));
if ( $memory_limit < 128 ) {
$php_infos [ 'memory' ][ 'message' ] = sprintf ( $this -> l ( 'PHP value: memory_limit recommended value is at least 128MB. your limit is currently set to %sMB' ), $memory_limit );
$php_infos [ 'memory' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
}
// Prestashop Configuration Check
if ( ! ( int ) Configuration :: get ( 'PS_SHOP_ENABLE' )) {
$prestashop_infos [ 'maintenance' ][ 'message' ] = $this -> l ( 'Be carefull, your shop is in maintenance mode, the module might not work in that mode' );
$prestashop_infos [ 'maintenance' ][ 'level' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
}
if ( _PS_MODE_DEV_ ) {
$prestashop_infos [ 'dev_mode' ][ 'message' ] = $this -> l ( 'The Prestashop constant _PS_MODE_DEV_ is enabled.' );
$prestashop_infos [ 'dev_mode' ][ 'level' ] = $this -> ps16x ? 'alert alert-info' : ( version_compare ( _PS_VERSION_ , '1.5' , '<' ) ? 'hint' : 'info' );
}
// URL issues for Ajax
/* $pass = true ;
if ( version_compare ( _PS_VERSION_ , '1.5' , '>=' )) {
if ( Shop :: isFeatureActive ()) {
$shop = Context :: getContext () -> shop ;
if ( $_SERVER [ 'HTTP_HOST' ] != $shop -> domain && $_SERVER [ 'HTTP_HOST' ] != $shop -> domain_ssl ) {
$pass = false ;
}
} else {
$urls = ShopUrl :: getShopUrls ( $this -> context -> shop -> id ) -> where ( 'main' , '=' , 1 ) -> getFirst ();
if ( $_SERVER [ 'HTTP_HOST' ] != $urls -> domain && $_SERVER [ 'HTTP_HOST' ] != $urls -> domain_ssl ) {
$pass = false ;
}
}
} elseif ( version_compare ( _PS_VERSION_ , '1.4' , '>=' )) {
if ( $_SERVER [ 'HTTP_HOST' ] != Configuration :: get ( 'PS_SHOP_DOMAIN' ) && $_SERVER [ 'HTTP_HOST' ] != Configuration :: get ( 'PS_SHOP_DOMAIN_SSL' )) {
$pass = false ;
}
}
if ( ! $pass ) {
$prestashop_infos [ 'wrong_domain' ][ 'message' ] = $this -> l ( 'Your are currently connected with the following domain name:' ) . ' <span style="color:navy">' . $_SERVER [ 'HTTP_HOST' ] . '</span><br />' .
$this -> l ( 'This one is different from the main shop domain name set in "Preferences > SEO & URLs":' ) . ' <span style="color:green">' . Configuration :: get ( 'PS_SHOP_DOMAIN' ) . '</span>' ;
$prestashop_infos [ 'wrong_domain' ][ 'level' ] = $this -> ps16x ? 'alert alert-danger' : 'error' ;
} */
if ( ! count ( $prestashop_infos )) {
$prestashop_info_ok = true ;
} else {
$prestashop_info_ok = false ;
}
if ( ! count ( $php_infos )) {
$php_info_ok = true ;
} else {
$php_info_ok = false ;
}
if ( ! count ( $module_infos )) {
$module_info_ok = true ;
} else {
$module_info_ok = false ;
}
$view_params = array ();
$view_params [ 'module_infos' ] = $module_infos ;
$view_params [ 'module_info_ok' ] = $module_info_ok ;
$view_params [ 'php_infos' ] = $php_infos ;
$view_params [ 'php_info_ok' ] = $php_info_ok ;
$view_params [ 'prestashop_infos' ] = $prestashop_infos ;
$view_params [ 'prestashop_info_ok' ] = $prestashop_info_ok ;
ob_start ();
phpinfo ( INFO_ALL & ~ INFO_CREDITS & ~ INFO_LICENSE & ~ INFO_ENVIRONMENT & ~ INFO_VARIABLES );
$phpinfos = ob_get_clean ();
$phpinfos = preg_replace ( '/(a:link.*)|(body, td, th, h1, h2.*)|(img.*)|(td, th.*)|(a:hover.*)|(class="center")/' , '' , $phpinfos );
$view_params [ 'phpinfo_str' ] = $phpinfos ;
$view_params [ 'psinfo_str' ] = $this -> prestashopInfo ();
$view_params [ 'dbinfo_str' ] = $this -> dbInfo ();
return ( $view_params );
}
public function dbInfo ()
{
$db_info = '' ;
$table = _DB_PREFIX_ . 'socolissimo_delivery_info' ;
$order_by = 'id_cart' ;
if ( Configuration :: get ( 'SOFLEXIBILITE_MODE' ) == self :: MODE_EXPEDITOR_THIRDPARTY ) {
$table = _DB_PREFIX_ . 'so_delivery' ;
$order_by = 'id' ;
}
$query = Db :: getInstance () -> executeS ( 'SHOW TABLES' );
$tables = array ();
foreach ( $query as $rows ) {
foreach ( $rows as $t ) {
$tables [ $t ] = 1 ;
}
}
if ( ! isset ( $tables [ $table ])) {
ConfigureMessage :: error ( $this -> l ( 'No So Colissimo table found in your database. Please save configuration to create the table and check again.' ));
return $this -> l ( 'No So Colissimo table found in your database. Please save configuration to create the table and check again.' );
}
$results = Db :: getInstance () -> executeS ( 'SELECT * FROM `' . $table . '` ORDER BY ' . $order_by . ' DESC LIMIT 5' );
$fields = array ();
$query = Db :: getInstance () -> ExecuteS ( 'SHOW COLUMNS FROM `' . $table . '`' );
foreach ( $query as $row ) {
$fields [] = $row [ 'Field' ];
}
$db_info = '<h1>' . $this -> l ( 'Database' ) . '</h1>' ;
$db_info .= '<pre>' ;
$db_info .= 'SHOW COLUMNS FROM `' . $table . '` : ' . print_r ( $fields , true );
$db_info .= 'SELECT * FROM `' . $table . '` ORDER BY ' . $order_by . ' DESC LIMIT 5 : ' . print_r ( $results , true );
$db_info .= '</pre>' ;
return ( $db_info );
}
public function prestashopInfo ()
{
$prestashop_info = '' ;
if ( $this -> ps15x ) {
$sort = 'ORDER by `name`,`id_shop`' ;
} else {
$sort = 'ORDER by `name`' ;
}
$results = Db :: getInstance () -> ExecuteS ( 'SELECT * FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` LIKE "PS_%" OR `name` LIKE "SOFLE%" ' . $sort );
$ps_configuration = null ;
foreach ( $results as $result ) {
if ( strpos ( $result [ 'name' ], 'KEY' ) || strpos ( $result [ 'name' ], 'EMAIL' ) || strpos ( $result [ 'name' ], 'PASSWORD' ) || strpos ( $result [ 'name' ], 'PASSWD' )
|| strpos ( $result [ 'name' ], 'CONTEXT_DATA' )
) {
continue ;
}
$value = $result [ 'value' ];
if ( base64_encode ( base64_decode ( $value , true )) === $value ) {
$value = base64_decode ( $value , true );
} else {
$value = $result [ 'value' ];
}
if ( @ serialize ( @ unserialize ( $value )) == $value ) {
$value = '<div class="print_r">' . print_r ( unserialize ( $value ), true ) . '</div>' ;
} else {
$value = Tools :: strlen ( $result [ 'value' ]) > 128 ? Tools :: substr ( $result [ 'value' ], 0 , 128 ) . '...' : $result [ 'value' ];
}
if ( $this -> ps15x ) {
$ps_configuration .= sprintf ( '%-50s %03d %03d : %s' . " \n " , $result [ 'name' ], $result [ 'id_shop' ], $result [ 'id_shop_group' ], $value );
} else {
$ps_configuration .= sprintf ( '%-50s : %s' . " \n " , $result [ 'name' ], $value );
}
}
$prestashop_info .= '<h1>Prestashop</h1>' ;
$prestashop_info .= '<pre>' ;
$prestashop_info .= 'Version: ' . _PS_VERSION_ . " \n \n " ;
$prestashop_info .= " \n " ;
$prestashop_info .= $ps_configuration ;
$prestashop_info .= '</pre>' . " \n \n " ;
return ( $prestashop_info );
}
public function displayForm ()
{
require_once ( dirname ( __FILE__ ) . '/shared/classes/configure_tab.class.php' );
$html = '' ;
$alert_class = array ();
$alert_class [ 'danger' ] = $this -> ps16x ? 'alert alert-danger' : 'error' ;
$alert_class [ 'warning' ] = $this -> ps16x ? 'alert alert-warning' : 'warn' ;
$alert_class [ 'success' ] = $this -> ps16x ? 'alert alert-success' : 'conf' ;
$alert_class [ 'info' ] = $this -> ps16x ? 'alert alert-info' : 'hint' ;
$this -> context -> smarty -> assign (
array (
'ps16x' => version_compare ( _PS_VERSION_ , '1.6' , '>=' ),
'soflexibilite_version' => $this -> version ,
'ps_version' => _PS_VERSION_ ,
'module_dir' => $this -> url ,
'images_url' => $this -> url . '/img/' ,
'tpl_url' => dirname ( __FILE__ ) . '/views/templates/admin' ,
'soflexibilite_info' => $this -> _backofficeInformations (),
'soflexibilite_theme' => Configuration :: get ( 'SOFLEXIBILITE_THEME' ),
'soflexibilite_google_map' => Configuration :: get ( 'SOFLEXIBILITE_GMAP' ),
'soflexibilite_mode' => Configuration :: get ( 'SOFLEXIBILITE_MODE' ),
'soflexibilite_login' => Configuration :: get ( 'SOFLEXIBILITE_LOGIN' ),
'soflexibilite_password' => Configuration :: get ( 'SOFLEXIBILITE_PASSWORD' ),
'soflexibilite_ws' => Configuration :: get ( 'SOFLEXIBILITE_WS' ),
'soflexibilite_point_list_url' => $this -> url . '/functions/check_login.php' ,
'soflexibilite_set_shiiping_cost_url' => $this -> url . '/functions/set_carriers_shipping_cost.php' ,
'selected_tab' => Tools :: getValue ( 'selected_tab' , '0' ),
'soflexibilite_form_action' => $_SERVER [ 'REQUEST_URI' ],
'alert_class' => $alert_class ,
'soflexibilite_insurrance' => Configuration :: get ( 'SOFLEXIBILITE_INSURRANCE' ),
'soflexibilite_insurrance_price' => Configuration :: get ( 'SOFLEXIBILITE_INSURRANCE_PRICE' ) ?
sprintf ( '%.2f' , Configuration :: get ( 'SOFLEXIBILITE_INSURRANCE_PRICE' )) : self :: INSURRANCE_PRICE_DEFAULT ,
'soflexibilite_insurrance_step' => Configuration :: get ( 'SOFLEXIBILITE_INSURRANCE_STEP' ) ?
sprintf ( '%.2f' , Configuration :: get ( 'SOFLEXIBILITE_INSURRANCE_STEP' )) : self :: INSURRANCE_STEP_DEFAULT ,
'soflexibilite_sub_phone' => Configuration :: get ( 'SOFLEXIBILITE_SUB_PHONE' ),
'soflexibilite_only_map' => Configuration :: get ( 'SOFLEXIBILITE_ONLY_MAP' ),
'soflexibilite_map_style' => Configuration :: get ( 'SOFLEXIBILITE_MAP_STYLE' ),
'soflexibilite_carriers' => $this -> getSoColissimoCarriers (),
'soflexibilite_carrier_wizard_token' => Tools :: getAdminToken ( 'AdminCarrierWizard' .
( int ) Tab :: getIdFromClassName ( 'AdminCarrierWizard' ) . ( int ) $this -> context -> employee -> id )
));
$this -> autoAddCSS ( $this -> _path . 'css/configuration.css' , 'all' );
$this -> autoAddJS ( $this -> _path . 'js/configuration.js' );
if ( $this -> ps15x ) {
$this -> autoAddCSS ( $this -> _path . 'css/jquery.qtip.min.css' , 'all' );
$this -> autoAddJS ( $this -> _path . 'js/jquery.qtip.min.js' );
}
$tab_list = array ();
$tab_list [] = array ( 'id' => 'soflexibilite' , 'img' => 'soflexibilite' , 'name' => 'Colissimo – web service' , 'selected' => true );
$tab_list [] = array ( 'id' => 'informations' , 'img' => 'information' , 'name' => 'Informations' , 'selected' => false );
$tab_list [] = array ( 'id' => 'credentials' , 'img' => 'key' , 'name' => $this -> l ( 'Credentials' ), 'selected' => false );
$tab_list [] = array ( 'id' => 'param' , 'img' => 'cog_edit' , 'name' => 'Configuration' , 'selected' => false );
$tab_list [] = array ( 'id' => 'personalization' , 'img' => 'color_management' , 'name' => $this -> l ( 'Personalization' ), 'selected' => false );
$tab_list [] = array ( 'id' => 'carriers' , 'img' => 'lorry' , 'name' => $this -> l ( 'Carriers' ), 'selected' => false );
$html .= ConfigureMessage :: display ();
$html .= $this -> context -> smarty -> fetch ( dirname ( __FILE__ ) . '/views/templates/admin/header.tpl' );
$html .= ConfigureTab :: generateTabs ( $tab_list );
$html .= $this -> context -> smarty -> fetch ( dirname ( __FILE__ ) . '/views/templates/admin/configuration.tpl' );
$html .= $this -> context -> smarty -> fetch ( dirname ( __FILE__ ) . '/views/templates/admin/glossary.tpl' );
return $html ;
}
protected function getSoColissimoCarriers ()
{
$sql = ' SELECT c .* , cl . delay
FROM `'._DB_PREFIX_.'carrier` c
LEFT JOIN `'._DB_PREFIX_.'carrier_lang` cl ON ( c . `id_carrier` = cl . `id_carrier` AND cl . `id_lang` = '.(int)$this->context->language->id.' )
WHERE c . `deleted` = 0
AND c . `external_module_name` = " soflexibilite "
GROUP BY c . `id_carrier` ' ;
if ( $this -> ps15x ) {
$sql .= '
ORDER BY c . `position` ASC ' ;
}
$carriers = Db :: getInstance () -> executeS ( $sql );
if ( ! is_array ( $carriers )) {
$carriers = array ();
ConfigureMessage :: error ( $this -> l ( 'Beware : you do not have any So Colissimo carrier linked to this module. A new install or reset is necessary.' ));
} else {
foreach ( array_keys ( $carriers ) as $key ) {
$carriers [ $key ][ 'logo' ] = __PS_BASE_URI__ . 'img/s/' . ( int ) $carriers [ $key ][ 'id_carrier' ] . '.jpg' ;
if ( version_compare ( _PS_VERSION_ , '1.5.4.1' , '>=' )) {
$carriers [ $key ][ 'conf_url' ] = '?controller=AdminCarrierWizard&token=' . Tools :: getAdminToken ( 'AdminCarrierWizard' . ( int ) Tab :: getIdFromClassName ( 'AdminCarrierWizard' ) . ( int ) $this -> context -> employee -> id ) . '&id_carrier=' . ( int ) $carriers [ $key ][ 'id_carrier' ];
} elseif ( $this -> ps15x ) {
$carriers [ $key ][ 'conf_url' ] = '?controller=AdminCarriers&id_carrier=' . ( int ) $carriers [ $key ][ 'id_carrier' ] . '&updatecarrier&token=' . Tools :: getAdminToken ( 'AdminCarriers' . ( int ) Tab :: getIdFromClassName ( 'AdminCarriers' ) . ( int ) $this -> context -> employee -> id );
} else {
$carriers [ $key ][ 'conf_url' ] = '?tab=AdminCarriers&id_carrier=' . ( int ) $carriers [ $key ][ 'id_carrier' ] . '&updatecarrier&token=' . Tools :: getAdminToken ( 'AdminCarriers' . ( int ) Tab :: getIdFromClassName ( 'AdminCarriers' ) . ( int ) $this -> context -> employee -> id );
}
}
}
return ( $carriers );
}
/* HOOKS FOR BACKWARD COMPATIBILITY - PRESTASHOP 1.4 */
public function hookNewOrder ( $params )
{
return ( $this -> hookActionValidateOrder ( $params ));
}
public function hookAdminOrder ( $params )
{
return ( $this -> hookDisplayAdminOrder ( $params ));
}
public function hookBeforeCarrier ( $params )
{
return ( $this -> hookDisplayBeforeCarrier ( $params ));
}
public function hookHeader ()
{
return $this -> hookDisplayHeader ();
}
public function hookBackOfficeHeader ()
{
if ( ! Configuration :: get ( 'SOCOLISSIMO_PERSONAL_DATA' )) {
if ( version_compare ( _PS_VERSION_ , '1.5' , '<' ) || ! method_exists ( $this -> context -> controller , 'addJQuery' )) {
return '<script type="text/javascript" src="' . __PS_BASE_URI__ . ' js / jquery / jquery . fancybox - 1.3 . 4. js " ></script>
< link type = " text/css " rel = " stylesheet " href = " '.__PS_BASE_URI__.'css/jquery.fancybox-1.3.4.css " /> ' ;
}
}
}
public function hookUpdateCarrier ( $params )
{
return ( $this -> hookActionCarrierUpdate ( $params ));
}
private function _hookSetup ( $action )
{
if ( $this -> ps15x ) {
$expectedHooks = array (
'actionValidateOrder' ,
'displayAdminOrder' ,
'displayBeforeCarrier' ,
'displayHeader' ,
'actionCarrierUpdate'
);
} else {
$expectedHooks = array (
'newOrder' ,
'adminOrder' ,
'beforeCarrier' ,
'header' ,
'updateCarrier' ,
'backOfficeHeader' ,
'processCarrier' ,
);
}
$pass = true ;
if ( $action == SoFlexibilite :: ADD ) {
foreach ( $expectedHooks as $expectedHook ) {
if ( ! $this -> registerHook ( $expectedHook )) {
$pass = false ;
}
}
}
if ( $action == SoFlexibilite :: REMOVE ) {
foreach ( $expectedHooks as $expectedHook ) {
if ( ! $this -> unregisterHook ( $expectedHook )) {
$pass = false ;
}
}
}
return ( $pass );
}
public function hookActionCarrierUpdate ( $params )
{
if ( in_array (( int )( $params [ 'id_carrier' ]), $this -> id_carrier_so )) {
if ( $this -> ps15x ) {
Configuration :: updateGlobalValue ( $this -> id_carrier_so_keys [( int )( $params [ 'id_carrier' ])], ( int )( $params [ 'carrier' ] -> id ), false );
} else {
Configuration :: updateValue ( $this -> id_carrier_so_keys [( int )( $params [ 'id_carrier' ])], ( int )( $params [ 'carrier' ] -> id ), false );
}
}
}
public function hookActionValidateOrder ( $params )
{
$check_address = new Address (( int ) $params [ 'cart' ] -> id_address_delivery );
if ( Validate :: isLoadedObject ( $check_address )) {
if ( strpos ( $check_address -> company , 'So Colissimo' ) !== false ) {
return ( false );
}
}
if ( in_array ( $params [ 'order' ] -> id_carrier , $this -> id_carrier_so )) {
if ( ! in_array ( $params [ 'order' ] -> id_carrier , array ( $this -> id_carrier_so [ 'SOFLEXIBILITE_DOM_ID' ], $this -> id_carrier_so [ 'SOFLEXIBILITE_DOS_ID' ]))) {
$soDelivery = new SoFlexibiliteDelivery (( int ) $params [ 'cart' ] -> id , ( int ) $params [ 'cart' ] -> id_customer );
$soDelivery -> loadDelivery ();
// OCARAT modification de création d'adresse a partir de la facturation
2016-05-26 10:19:16 +02:00
// if (!($id_address_new = (int)$soDelivery->createAddressForPickupPoint((int)$params['cart']->id_address_invoice))) {
if ( ! ( $id_address_new = ( int ) $soDelivery -> createAddressForPickupPoint (( int ) $params [ 'cart' ] -> id_address_delivery ))) {
2016-05-09 17:43:57 +02:00
return ( false );
}
if ( $this -> ps15x ) {
$params [ 'order' ] -> id_address_delivery = $id_address_new ;
} else {
$params [ 'order' ] -> id_address_delivery = $id_address_new ;
$params [ 'order' ] -> save ();
}
// Change pickup address by customer address invoice in case of a problem with the pickup
/* $address_invoice = new Address (( int ) $params [ 'cart' ] -> id_address_invoice );
if ( Validate :: isLoadedObject ( $address_invoice )) {
$soDelivery -> address1 = $address_invoice -> address1 ;
$soDelivery -> address2 = $address_invoice -> address2 ;
$soDelivery -> postcode = $address_invoice -> postcode ;
$soDelivery -> city = $address_invoice -> city ;
$soDelivery -> country = Country :: getIsoById (( int ) $address_invoice -> id_country );
} */
// OCARAT modif update for customizations
if ( $this -> ps15x ) {
$sql = 'UPDATE `' . _DB_PREFIX_ . ' cart_product `
SET `id_address_delivery` = '.(int)$id_address_new.'
WHERE `id_cart` = '.(int)$params[' order ' ] -> id_cart ;
Db :: getInstance () -> execute ( $sql );
$sql = 'UPDATE `' . _DB_PREFIX_ . ' customization `
SET `id_address_delivery` = '.(int)$id_address_new.'
WHERE `id_cart` = '.(int)$params[' order ' ] -> id_cart ;
Db :: getInstance () -> execute ( $sql );
}
$soDelivery -> id_order = ( int ) $params [ 'order' ] -> id ;
// Check phone number, if empty at least we need to put something, phone is compulsory to register on prestashop, we get it
2016-05-26 10:19:16 +02:00
// $address = new Address((int)$params['cart']->id_address_invoice);
$address = new Address (( int ) $params [ 'cart' ] -> id_address_delivery );
2016-05-09 17:43:57 +02:00
$address_delivery = new Address ( $id_address_new );
if ( Validate :: isLoadedObject ( $address_delivery )) {
$soDelivery -> lastname = $address -> lastname ;
}
$soDelivery -> saveDelivery ();
if ( Validate :: isLoadedObject ( $address )) {
if ( is_null ( $soDelivery -> telephone ) || empty ( $soDelivery -> telephone ) || Tools :: strlen ( $soDelivery -> telephone ) < 7 ) {
$soDelivery -> telephone = $address -> phone_mobile ? $address -> phone_mobile : ( $address -> phone ? $address -> phone : '' );
}
}
$soDelivery -> saveDelivery ();
} else {
$soDelivery = new SoFlexibiliteDelivery (( int ) $params [ 'cart' ] -> id , ( int ) $params [ 'cart' ] -> id_customer );
$soDelivery -> loadDelivery ();
switch ( $params [ 'order' ] -> id_carrier ) {
case ( $this -> id_carrier_so [ 'SOFLEXIBILITE_DOM_ID' ]) :
$delivery_mode = 'DOM' ;
break ;
case ( $this -> id_carrier_so [ 'SOFLEXIBILITE_DOS_ID' ]) :
$delivery_mode = 'DOS' ;
break ;
default :
$delivery_mode = 'DOM' ;
break ;
}
// Ocarat change delivery address to invoice one
2016-05-26 10:19:16 +02:00
// $address = new Address((int)$params['cart']->id_address_invoice);
$address = new Address (( int ) $params [ 'cart' ] -> id_address_delivery );
2016-05-09 17:43:57 +02:00
if ( ! Validate :: isLoadedObject ( $address )) {
return ( false );
}
$customer = new Customer (( int ) $params [ 'cart' ] -> id_customer );
if ( ! Validate :: isLoadedObject ( $customer )) {
return ( false );
}
$soDelivery -> type = $delivery_mode ;
$soDelivery -> id_order = ( int ) $params [ 'order' ] -> id ;
$soDelivery -> id_point = null ;
$soDelivery -> firstname = $address -> firstname ;
$soDelivery -> lastname = $address -> lastname ;
$soDelivery -> company = $address -> company ;
$soDelivery -> telephone = ! empty ( $soDelivery -> telephone ) ? $soDelivery -> telephone : $address -> phone_mobile ;
$soDelivery -> email = ! empty ( $soDelivery -> email ) ? $soDelivery -> email : $customer -> email ;
$soDelivery -> libelle = null ;
$soDelivery -> indice = null ;
$soDelivery -> postcode = $address -> postcode ;
$soDelivery -> city = $address -> city ;
$soDelivery -> country = Country :: getIsoById ( $address -> id_country );
$soDelivery -> address1 = $address -> address1 ;
$soDelivery -> address2 = $address -> address2 ;
$soDelivery -> lieudit = null ;
// Check phone number, if empty at least we need to put something, phone is compulsory to register on prestashop, we use it
if ( is_null ( $soDelivery -> telephone ) || empty ( $soDelivery -> telephone ) || Tools :: strlen ( $soDelivery -> telephone ) < 7 ) {
$soDelivery -> telephone = $address -> phone_mobile ? $address -> phone_mobile : ( $address -> phone ? $address -> phone : '' );
}
$soDelivery -> saveDelivery ();
}
} else {
$soDelivery = new SoFlexibiliteDelivery ();
$soDelivery -> removeDelivery (( int ) $params [ 'cart' ] -> id );
}
}
public function hookDisplayAdminOrder ( $params )
{
$order = new Order (( int ) $params [ 'id_order' ]);
if ( ! Validate :: isLoadedObject ( $order )) {
return ( false );
}
$soDelivery = new SoFlexibiliteDelivery (( int ) $order -> id_cart , ( int ) $order -> id_customer );
if ( ! $soDelivery -> loadDelivery () || ! $soDelivery -> isLoadedObject ()) {
return ( false );
}
// Customer Info
$customer = new Customer ( $order -> id_customer );
$customer_address = new Address ( $order -> id_address_delivery );
if ( ! Validate :: isLoadedObject ( $customer ) || ! Validate :: isLoadedObject ( $customer_address )) {
return ( false );
}
require_once dirname ( __FILE__ ) . '/classes/SoFlexibiliteWebService.php' ;
// Customer Name
2016-06-03 11:18:35 +02:00
/* $address = Db :: getInstance () -> ExecuteS ( 'SELECT * FROM ps_socolissimo_delivery_info WHERE id_cart = ' . pSQL (( int ) $order -> id_cart ));
2016-05-20 17:45:26 +02:00
if ( count ( $address ) > 0 ) {
$address = $address [ 0 ];
}
if ( ! empty ( $address [ 'prname' ]) && ! empty ( $address [ 'prname' ])) {
$fullname = sprintf ( '%s %s' , $address [ 'prfirstname' ], $address [ 'prname' ]);
2016-06-03 11:18:35 +02:00
} else */
if ( ! empty ( $soDelivery -> firstname ) && ! empty ( $soDelivery -> lastname )) {
2016-05-09 17:43:57 +02:00
$fullname = sprintf ( '%s %s' , $soDelivery -> firstname , $soDelivery -> lastname );
} else {
$fullname = sprintf ( '%s %s' , $customer_address -> firstname , $customer_address -> lastname );
}
if ( strpos ( $fullname , ' c/o ' )) {
$fullname = reset ( explode ( ' c/o ' , $fullname ));
}
// Customer Email
$email = null ;
if ( ! empty ( $soDelivery -> ceemail )) {
$email = trim ( $soDelivery -> email );
} elseif ( ! empty ( $customer -> email )) {
$email = trim ( $customer -> email );
}
// Delivery Informations
if ( ! empty ( $soDelivery -> informations )) {
$result = explode ( '|' , wordwrap ( $soDelivery -> informations , 64 , '|' , true ));
if ( isset ( $result [ 1 ])) {
$informations = sprintf ( '%s...' , $result [ 0 ]);
} else {
$informations = $result [ 0 ];
}
} else {
$informations = null ;
}
$soflexibilite_bo_title = 'Colissimo' ;
if ( in_array ( $soDelivery -> type , array ( 'BPR' , 'BDP' , 'CDI' ))) {
$soflexibilite_bo_title = $this -> l ( 'Delivery at post-office' );
} elseif ( in_array ( $soDelivery -> type , array ( 'A2P' , 'CMT' ))) {
$soflexibilite_bo_title = $this -> l ( 'Delivery in a shopkeeper' );
} elseif ( in_array ( $soDelivery -> type , array ( 'DOM' , 'BOM' ))) {
$soflexibilite_bo_title = $this -> l ( 'Delivery at home (without signature)' );
} elseif ( in_array ( $soDelivery -> type , array ( 'DOS' , 'BOS' ))) {
$soflexibilite_bo_title = $this -> l ( 'Delivery at home (with signature)' );
}
$relay_informations = SoFlexibiliteWebService :: getRelayStatic ( sprintf ( '%06s' , $soDelivery -> id_point ));
$soflexibilite_delivery_address = array (
'name' => $fullname ,
'libelle' => in_array ( $soDelivery -> type , array ( 'DOM' , 'DOS' , 'BOM' , 'BOS' )) ? '' : $soDelivery -> libelle ,
'prid' => $soDelivery -> id_point ? sprintf ( '%06s' , $soDelivery -> id_point ) : null ,
2016-06-03 11:18:35 +02:00
/*'company' => $soDelivery->company ? $soDelivery->company : $customer_address->company,*/
'company' => $soDelivery -> company ,
2016-05-09 17:43:57 +02:00
'prname' => isset ( $relay_informations -> nom ) ? $relay_informations -> nom : '' ,
'address1' => isset ( $relay_informations -> adresse1 ) ? $relay_informations -> adresse1 : (
in_array ( $soDelivery -> type , array ( 'DOM' , 'DOS' , 'BOM' , 'BOS' )) ?
$soDelivery -> lieudit :
$soDelivery -> address1
),
'address2' => isset ( $relay_informations -> adresse2 ) ? $relay_informations -> adresse2 : (
in_array ( $soDelivery -> type , array ( 'DOM' , 'DOS' , 'BOM' , 'BOS' )) ?
$soDelivery -> address1 :
$soDelivery -> address2
),
'postcode' => isset ( $relay_informations -> codePostal ) ? $relay_informations -> codePostal : $soDelivery -> postcode ,
'city' => isset ( $relay_informations -> localite ) ? $relay_informations -> localite : $soDelivery -> city ,
'country' => isset ( $relay_informations -> libellePays ) ? $relay_informations -> libellePays : (
Tools :: strlen ( $soDelivery -> country ) == 2 ?
2016-06-03 11:18:35 +02:00
Country :: getNameById ( $this -> context -> employee -> id_lang , strtolower ( $soDelivery -> country ) == 'fr' ? 8 : Country :: getByIso ( $soDelivery -> country )) :
2016-05-09 17:43:57 +02:00
$soDelivery -> country
),
'iso_country' => isset ( $relay_informations -> codePays ) ? $relay_informations -> codePays : $soDelivery -> country ,
'mobile' => $this -> betterPhoneNumber ( $soDelivery -> telephone ),
'email' => $email ,
'informations' => str_replace ( '\\' , '' , $informations ),
'search_address' => sprintf ( '%s, %s %s, %s' , $soDelivery -> address1 , $soDelivery -> postcode , $soDelivery -> city , $soDelivery -> country )
);
$this -> context -> smarty -> assign (
array (
'soflexibilite_bo_title' => $soflexibilite_bo_title ,
'images_url' => $this -> url . '/img/' ,
'soflexibilite_socolissimo_logo' => $this -> url . '/img/colissimo_order.png' ,
'soflexibilite_delivery_address' => $soflexibilite_delivery_address ,
'soflexibilite_is_ps16x' => $this -> ps16x ,
'soflexibilite_version' => $this -> ps15x ,
'soflexibilite_url' => $this -> url ,
'soflexibilite_change_pickup_url' => $this -> url . '/functions/changepickup.php' ,
'soflexibilite_save_info_commande_url' => $this -> saveInfoCommande ,
'soflexibilite_id_cart' => $soDelivery -> id_cart ,
'soflexibilite_id_customer' => $soDelivery -> id_customer ,
'soflexibilite_id_order' => $order -> id ,
'soflexibilite_point_list_url' => $this -> point_list_url
)
);
$this -> autoAddJS ( $this -> _path . 'js/adminorder.js' );
$this -> autoAddCSS ( $this -> _path . 'css/soflexibiliteAdminOrder.css' , 'all' );
return ( $this -> display ( __FILE__ , 'views/templates/hook/displayAdminOrder.tpl' ));
}
public function hookDisplayBeforeCarrier ( $params )
{
$so_found = FALSE ;
foreach ( $params [ 'carriers' ] as $carrier ) {
if ( in_array (( int ) $carrier [ 'id_carrier' ], $this -> id_carrier_so )) {
$so_found = TRUE ;
break ;
}
}
if ( ! $so_found ) {
return ;
}
$this -> context -> smarty -> assign ( 'ps16x' , $this -> ps16x );
if ( $this -> ps15x ) {
$customerAddresses = $this -> context -> customer -> getAddresses (( int ) $this -> context -> cookie -> id_lang );
$id_delivery_address = ( int ) $this -> context -> cart -> id_address_delivery ;
} else {
$customerAddresses = Db :: getInstance () -> ExecuteS ( 'SELECT * FROM ' . _DB_PREFIX_ . 'address WHERE id_customer='
. ( int ) $this -> context -> cookie -> id_customer );
$id_delivery_address = ( int ) $params [ 'cart' ] -> id_address_delivery ;
}
$mobile = '' ;
$inputs = array ();
foreach ( $customerAddresses as $address ) {
if (( int ) $address [ 'id_address' ] === $id_delivery_address ) {
$inputs [] = array (
'id_address' => $address [ 'id_address' ],
'alias' => $address [ 'alias' ],
'company' => $address [ 'company' ],
'firstname' => $address [ 'firstname' ],
'lastname' => $address [ 'lastname' ],
'address1' => $address [ 'address1' ],
'address2' => $address [ 'address2' ],
'postcode' => $address [ 'postcode' ],
'city' => $address [ 'city' ],
2016-05-27 17:22:48 +02:00
'phone' => ( ! empty ( $address [ 'phone_mobile' ]) ? $address [ 'phone_mobile' ] : $address [ 'phone' ]),
2016-05-09 17:43:57 +02:00
'country' => Country :: getIsoById ( $address [ 'id_country' ]),
'abdefault' => $address [ 'id_address' ] == ( int ) $params [ 'cart' ] -> id_address_delivery ? '1' : '0'
);
if ( isset ( $address [ 'phone_mobile' ])) {
$phone_mobile = '/^((\+|00)33\s?|0)[67](\s?\d{2}){4}$/i' ;
$phone_mobile_be = '/^((\+|00)32\s?|0)4(60|[789]\d)(\s?\d{2}){3}$/i' ;
if ( preg_match ( $phone_mobile , $address [ 'phone_mobile' ]) || preg_match ( $phone_mobile_be , $address [ 'phone_mobile' ])) {
$mobile = $address [ 'phone_mobile' ];
}
}
}
}
// Check if went to cart previously, changed page, then came back --> Load delivery_mode for "mon domicile"
$soDelivery = new SoFlexibiliteDelivery (( int ) $params [ 'cart' ] -> id , ( int ) $params [ 'cart' ] -> id_customer );
$soDelivery -> loadDelivery ();
if ( ! is_null ( $soDelivery -> type ) && Tools :: strlen ( $soDelivery -> type ) && ( $soDelivery -> type == 'DOM' || $soDelivery -> type == 'DOS' )) {
$soflexibilite_delivery_mode = $soDelivery -> type ;
} else {
$soflexibilite_delivery_mode = Configuration :: get ( 'SOFLEXIBILITE_HOME_MODE' );
}
// !Check if went to cart previously
$force_dos_delivery = false ;
$cart_price = 0 ;
if ( $params [ 'cart' ] -> id ) {
$cart_price = Cart :: getTotalCart (( int ) $params [ 'cart' ] -> id , true );
}
if ( Configuration :: get ( 'SOFLEXIBILITE_FORCE_DOS' ) && Configuration :: get ( 'SOFLEXIBILITE_FORCE_DOS_VALUE' ) <= $cart_price ) {
$force_dos_delivery = true ;
}
$this -> context -> smarty -> assign (
array (
'soflexibilite_dom_id' => ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_DOM_ID' ],
'soflexibilite_dos_id' => ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_DOS_ID' ],
'soflexibilite_bpr_id' => ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_BPR_ID' ],
'soflexibilite_a2p_id' => ( int ) $this -> id_carrier_so [ 'SOFLEXIBILITE_A2P_ID' ],
'soflexibilite_cust_id' => $id_delivery_address ,
'inputs' => $inputs ,
2016-05-27 17:22:48 +02:00
'soflexibilite_mobile' => (( isset ( $mobile ) && ! empty ( $mobile )) ? $mobile : $address [ 'phone' ]),
2016-05-09 17:43:57 +02:00
'soflexibilite_point_list_url' => $this -> point_list_url ,
'getCustomerAddress' => $this -> getCustomerAddress ,
'saveDeliveryPoint' => $this -> saveDelivery_url ,
'initSoflexibiliteEnv' => $this -> url . '/functions/initSoflexibiliteEnv.php' ,
'checkPointSelectedOPC' => $this -> initSoflexibiliteEnv_url ,
'saveInfoCommande' => $this -> saveInfoCommande ,
'protocol' => $this -> protocol ,
'soflexibilite_cust_mail' => $params [ 'cookie' ] -> email ,
'soflexibilite_cart_id' => $params [ 'cart' ] -> id ,
'lang' => Language :: getIsoById ( $this -> id_lang ),
'signature' => ( self :: $home_delivery_mode == self :: HOME_DELIVERY_DOS ) ? 1 : 0 ,
'ps15x' => $this -> ps15x ,
'so_url' => $this -> url ,
'images_url' => $this -> url . '/img/' ,
'soflexibilite_bpr_active' => ( int ) SoFlexibiliteTools :: carrierIsEnabled ( $this -> id_carrier_so [ 'SOFLEXIBILITE_BPR_ID' ]),
'soflexibilite_a2p_active' => ( int ) SoFlexibiliteTools :: carrierIsEnabled ( $this -> id_carrier_so [ 'SOFLEXIBILITE_A2P_ID' ]),
'soflexibilite_delivery_mode' => $soflexibilite_delivery_mode ,
'soflexibilite_user_home_mode' => ( bool ) Configuration :: get ( 'SOFLEXIBILITE_USER_HOME_MODE' ),
'soflexibilite_force_dos' => $force_dos_delivery ,
'soflexibilite_only_map' => Configuration :: get ( 'SOFLEXIBILITE_ONLY_MAP' ),
'soflexibilite_map_style' => Configuration :: get ( 'SOFLEXIBILITE_MAP_STYLE' )
)
);
if ( $this -> ps15x ) {
$this -> autoAddCSS ( $this -> url . '/css/jquery.qtip.min.css' , 'all' );
$this -> autoAddJS ( $this -> url . '/js/jquery.qtip.min.js' );
}
$this -> autoAddCSS ( $this -> url . '/css/soflexibilite.css' , 'all' );
$this -> autoAddCSS ( $this -> url . '/css/soflexibilite' . Configuration :: get ( 'SOFLEXIBILITE_THEME' ) . '.css' , 'all' );
$this -> autoAddJS ( $this -> url . '/js/front_flexibilite.js' );
$this -> autoAddJS ( $this -> url . '/js/fcts.js' );
if ( Configuration :: get ( 'SOFLEXIBILITE_GMAP' )) {
$this -> autoAddJS ( 'https://maps.google.com/maps/api/js?sensor=false' );
}
return ( $this -> display ( __FILE__ , 'views/templates/hook/displayBeforeCarrier.tpl' ));
}
private function autoAddJS ( $url )
{
if ( $this -> ps15x ) {
return ( $this -> context -> controller -> addJS ( $url ));
}
echo '<script type="text/javascript" src="' . $url . '"></script>' ;
}
private function autoAddCSS ( $url , $media = null )
{
if ( $this -> ps15x ) {
return ( $this -> context -> controller -> addCSS ( $url , $media ));
}
echo '<link type="text/css" rel="stylesheet" href="' . $url . '">' ;
}
public function hookDisplayHeader ()
{
return false ;
}
private function betterPhoneNumber ( $nb )
{
$prefix = '' ;
$prefix_length = 0 ;
$retNb = '' ;
if ( preg_match ( '/^((\+)33)/i' , $nb )) {
$prefix = '+33 (0)' ;
$prefix_length = 3 ;
} elseif ( preg_match ( '/^((00)33)/i' , $nb )) {
$prefix = '0033 (0)' ;
$prefix_length = 4 ;
} elseif ( preg_match ( '/^((\+)32)/i' , $nb )) {
$prefix = '+32 (0)' ;
$prefix_length = 3 ;
} elseif ( preg_match ( '/^((00)32)/i' , $nb )) {
$prefix = '0032 (0)' ;
$prefix_length = 4 ;
}
if ( Tools :: strlen ( $prefix )) {
$nb = Tools :: substr ( $nb , $prefix_length );
}
$nb = strrev ( $nb );
$length = Tools :: strlen ( $nb );
for ( $i = 0 ; $i < $length ; $i += 1 ) {
if ( $i % 2 === 0 ) {
$retNb .= ' ' ;
}
$retNb .= $nb [ $i ];
}
$retNb = strrev ( $retNb );
return ( $prefix . $retNb );
}
public function isFlexibiliteEnabled ()
{
if ( $this -> ps15x ) {
return ( Module :: isEnabled ( $this -> name ));
}
return ( $this -> active );
}
public function getOrderShippingCost ( $params , $shipping_cost )
{
// if (!$this->isFlexibiliteEnabled() || $shipping_cost < 0) {
// return (false);
// }
//
// $address_delivery = new Address((int)$params->id_address_delivery);
// if (!Validate::isLoadedObject($address_delivery)) {
// // TODO
// // la fonction getOrderShippingCost de soflexibilite.php, retourne false si l'adresse de livraison n'est pas définie,
// // ce qui nous a posé un problème pour l'affichage des frais de livraison dans le panier avant que le client ne soit connecté,
// // car prestashop excluait les transporteurs socolissmo dans sa fonction getPackageShippingCost (//get external shipping cost from module) étant donné que le module retournait false.
//// return (false);
// }
2016-05-17 14:31:41 +02:00
/* if ( $this -> isOnlyExpendable ( $this -> context -> cart )) {
2016-05-09 17:43:57 +02:00
$shipping_cost = 5 ;
return $shipping_cost ;
2016-05-17 14:31:41 +02:00
} */
2016-05-09 17:43:57 +02:00
return (( float ) $shipping_cost );
}
public function isOnlyExpendable ( $cart ) {
$product_cats = array ();
foreach ( $cart -> getProducts () as $product ) {
$product_cats [] = ( int ) $product [ 'id_category_default' ];
}
$sales = Db :: getInstance () -> ExecuteS ( '
SELECT DISTINCT `id_sale`
FROM `'._DB_PREFIX_.'privatesale_category`
WHERE `id_category` IN ( '.implode(' , ', $product_cats).' )
' );
if ( $sales ) {
$cpt_sales = count ( $sales );
} else {
$cpt_sales = 0 ;
}
// si une seule vente et vente consommable on retourne true
if ( $cpt_sales == 1 && ( int ) $sales [ 0 ][ 'id_sale' ] == ( int ) _SHOP_PRIVATESALES_CONSUMABLE ) {
return true ;
}
return false ;
}
public function getOrderShippingCostExternal ( $params )
{
return true ;
}
public function hookProcessCarrier ( $params ) {
if ( in_array ( $params [ 'cart' ] -> id_carrier , $this -> id_carrier_so )) {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'socolissimo_delivery_info`
SET `ceemail` = " '.pSQL(Tools::getValue('so_custMail')).' " ,
`cephonenumber` = " '.pSQL(Tools::getValue('so_custPhone')).' "
WHERE `id_cart` = '.(int) $params[' cart ']->id.'
' );
} else {
Db :: getInstance () -> Execute ( '
DELETE FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $params[' cart ']->id.'
LIMIT 1
' );
}
}
}