1416 lines
49 KiB
PHP
Executable File
1416 lines
49 KiB
PHP
Executable File
<?php
|
||
/**
|
||
* MODULE PRESTASHOP OFFICIEL CHRONOPOST
|
||
*
|
||
* LICENSE : All rights reserved - COPY AND REDISTRIBUTION FORBIDDEN WITHOUT PRIOR CONSENT FROM OXILEO
|
||
* LICENCE : Tous droits réservés, le droit d'auteur s'applique - COPIE ET REDISTRIBUTION INTERDITES SANS ACCORD EXPRES D'OXILEO
|
||
*
|
||
* @author Oxileo SAS <contact@oxileo.eu>
|
||
* @copyright 2001-2014 Oxileo SAS
|
||
* @license Proprietary - no redistribution without authorization
|
||
*/
|
||
|
||
// CONSTS
|
||
// PHP <5.3
|
||
if(!defined('_MYDIR_')) define('_MYDIR_', dirname(__FILE__));
|
||
|
||
require_once(_MYDIR_.'/classes/range/RangePrice.php');
|
||
require_once(_MYDIR_.'/classes/range/RangeWeight.php');
|
||
|
||
define("MIN_VERSION", "1.6");
|
||
define("MAX_VERSION", "1.7");
|
||
|
||
class Chronopost extends CarrierModule
|
||
{
|
||
private $_postErrors = array();
|
||
public $id_carrier;
|
||
|
||
public static $productCodes = array(
|
||
'CHRONOPOST_CARRIER_ID' => "01",
|
||
'CHRONORELAIS_CARRIER_ID'=>"86",
|
||
'CHRONO10_CARRIER_ID'=>"02",
|
||
'CHRONO18_CARRIER_ID'=>16,
|
||
'CHRONOEXPRESS_CARRIER_ID'=>17,
|
||
'CHRONOCLASSIC_CARRIER_ID'=>44);
|
||
|
||
|
||
public static $productCodesBAL = array(
|
||
'CHRONOPOST_CARRIER_ID' => "01",
|
||
'CHRONORELAIS_CARRIER_ID'=>86,
|
||
'CHRONO10_CARRIER_ID'=>"02",
|
||
'CHRONO18_CARRIER_ID'=>16,
|
||
'CHRONOEXPRESS_CARRIER_ID'=>17,
|
||
'CHRONOCLASSIC_CARRIER_ID'=>44);
|
||
|
||
|
||
// Module config at install-time
|
||
private static $_config = array(
|
||
'chronorelais'=>array(
|
||
'name' => 'Chronopost - Livraison express en point relais',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => true,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
// shown in FO during carrier selection. length limited to 128 char I REPEAT 128 CHARS
|
||
'delay' => array('fr'=>'Colis livré le lendemain avant 13 h dans le relais Pickup de votre choix. Vous serez averti par e-mail et SMS.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronorelais',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONORELAIS_CARRIER_ID'
|
||
),
|
||
'chronopost'=>array(
|
||
'name' => 'Chronopost - Livraison express à domicile',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => true,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
'delay' => array('fr'=>'Colis livré le lendemain matin avant 13h à votre domicile. La veille de la livraison, vous êtes averti par e-mail et SMS.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronopost',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONOPOST_CARRIER_ID'
|
||
),
|
||
'chrono10'=>array(
|
||
'name' => 'Chronopost - Livraison express à domicile',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => true,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
'delay' => array('fr'=>'Colis livré le lendemain matin avant 10h à votre domicile. La veille de la livraison, vous êtes averti par e-mail et SMS.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronopost',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONO10_CARRIER_ID'
|
||
),
|
||
'chrono18'=>array(
|
||
'name' => 'Chronopost - Livraison express à domicile',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => false,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
'delay' => array('fr'=>'Colis livré le lendemain matin avant 18h à votre domicile. La veille de la livraison, vous êtes averti par e-mail et SMS.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronopost',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONO18_CARRIER_ID'
|
||
),
|
||
'chronoexpress'=>array(
|
||
'name' => 'Chrono Express',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => true,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
'delay' => array('fr'=>'Colis livré en 1 à 3 jours vers l\'Europe, en 48h vers les DOM et en 2 à 5 jours vers le reste du monde.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronoexpress',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONOEXPRESS_CARRIER_ID'
|
||
),
|
||
'chronoclassic'=>array(
|
||
'name' => 'Chrono Classic',
|
||
'id_tax_rules_group' => 1,
|
||
'url' => 'http://www.chronopost.fr/expedier/inputLTNumbersNoJahia.do?lang=fr_FR&listeNumeros=@',
|
||
'active' => true,
|
||
'deleted' => 0,
|
||
'shipping_handling' => false,
|
||
'range_behavior' => 0,
|
||
'is_module' => false,
|
||
'delay' => array('fr'=>'Colis livré en 1 à 3 jours vers l\'Europe.'),
|
||
'shipping_external'=> true,
|
||
'external_module_name'=> 'chronopost',
|
||
'need_range' => true,
|
||
// .jpg file in img directory
|
||
'logo_filename'=> 'chronoexpress',
|
||
// name of the config key to contain carrier ID after module init
|
||
'configuration_item'=> 'CHRONOCLASSIC_CARRIER_ID'
|
||
)
|
||
);
|
||
|
||
public function __construct()
|
||
{
|
||
$this->name = 'chronopost';
|
||
$this->tab = 'shipping_logistics';
|
||
$this->version = 'TO3.0.0';
|
||
$this->module_key='2ae005267ca01c3e4ead54cef103d6cf';
|
||
$this->author = 'Oxileo pour Chronopost';
|
||
|
||
parent::__construct();
|
||
|
||
$this->displayName = $this->l('Chronopost & ChronoRelais');
|
||
$this->description = $this->l('Prise en charge du transporteur Chronopost et des points relais Chrono Relais');
|
||
$this->confirmUninstall = $this->l('Attention, une fois ce module désinstallé, vous ne pourrez plus éditer d\'étiquettes de transport Chronopost ni proposer la livraison en point relais à vos clients. Etes-vous sûr de vouloir continuer ?');
|
||
|
||
// Check is SOAP is available
|
||
if(!extension_loaded('soap')) $this->warning.=$this->l('L\'extension SOAP n\'est pas disponible ou configurée sur ce serveur '
|
||
.'; le module ne fonctionnera pas sans cette extension ! Rapprochez-vous de votre hébergeur afin d\'activer SOAP sur votre '
|
||
.' installation PHP.');
|
||
if(!self::checkPSVersion())
|
||
$this->warning.=$this->l('Ce module n\'est pas compatible avec votre installation Prestashop. Vous pouvez vous rendre sur le site Chronopost.fr pour télécharger gratuitement une version compatible.');
|
||
|
||
// Check is module is properly configured
|
||
if(Tools::strlen(Configuration::get('CHRONOPOST_GENERAL_ACCOUNT'))<8)
|
||
$this->warning.=$this->l('Vous devez configurer le module Chronopost avec vos informations de contrat Chronopost. Veuillez vous connecter à l\'adresse suivante : <a href="http://www.mychrono.chronopost.fr" target="_blank">www.mychrono.chronopost.fr</a> si vous ne disposez pas de contrat Chronopost.');
|
||
|
||
|
||
}
|
||
|
||
public function preInstall()
|
||
{
|
||
if (!self::checkPSVersion()) {
|
||
$this->context->controller->errors[] = 'Ce module n\'est pas compatible avec votre installation Prestashop. Vous pouvez vous rendre sur le site <a href="http://www.chronopost.fr/transport-express/livraison-colis/accueil/produits-tarifs/expertise-sectorielle/e-commerce/plateformes">Chronopost.fr</a> pour télécharger gratuitement une version compatible.';
|
||
return false;
|
||
}
|
||
if (!parent::install()) return false;
|
||
|
||
// Check for SOAP
|
||
if(!extension_loaded('soap')) return false;
|
||
|
||
// Check PHP 5.2+
|
||
if(version_compare(phpversion(), '5.2.0')<0) return false;
|
||
|
||
// Admin tab
|
||
if(!$this->_adminInstall()) return false;
|
||
|
||
|
||
// register hooks
|
||
if(
|
||
!$this->registerHook('extraCarrier') || // For point relais GMap
|
||
!$this->registerHook('updateCarrier') || // For update of carrier IDs
|
||
!$this->registerHook('top') || //
|
||
!$this->registerHook('newOrder') || // Processing of selected BT, NOTE : processCarrier apparently not what we want
|
||
!$this->registerHook('header') || //
|
||
!$this->registerHook('backOfficeHeader') || //
|
||
!$this->registerHook('adminOrder')
|
||
) return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
/** INSTALLATION-RELATED FUNCTIONS **/
|
||
public function install()
|
||
{
|
||
if (Shop::isFeatureActive())
|
||
Shop::setContext(Shop::CONTEXT_ALL);
|
||
|
||
DB::getInstance()->execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'_chrono_calculateproducts_cache2` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`postcode` varchar(10) NOT NULL,
|
||
`country` varchar(2) NOT NULL,
|
||
`chrono10` tinyint(1) NOT NULL,
|
||
`chrono18` tinyint(1) NOT NULL,
|
||
`chronoclassic` tinyint(1) NOT NULL,
|
||
`last_updated` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
|
||
|
||
Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'chrono_cart_relais` (
|
||
`id_cart` int(10) NOT NULL,
|
||
`id_pr` varchar(10) NOT NULL,
|
||
PRIMARY KEY (`id_cart`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;');
|
||
|
||
Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'chrono_lt_history` (
|
||
`id_order` int(10) NOT NULL,
|
||
`lt` varchar(20) NOT NULL,
|
||
`product` varchar(2) NOT NULL,
|
||
`zipcode` varchar(10) NOT NULL,
|
||
`country` varchar(2) NOT NULL,
|
||
`insurance` int(10) NOT NULL,
|
||
`city` varchar(32) NOT NULL,
|
||
PRIMARY KEY (`id_order`, `lt`)
|
||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;');
|
||
|
||
// pre install
|
||
if(!$this->preInstall()) return false;
|
||
|
||
// init config
|
||
if(
|
||
!Configuration::updateValue('CHRONOPOST_SECRET', sha1(microtime(true).mt_rand(10000,90000)))
|
||
|| !Configuration::updateValue('CHRONOPOST_CORSICA_SUPPLEMENT', '19.60')
|
||
) return false;
|
||
|
||
// add carriers in back office
|
||
if (!$this->createChronopostCarriers(self::$_config))
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
private function _adminInstall()
|
||
{
|
||
$tab_export = new Tab();
|
||
$tab_export->class_name = 'AdminExportChronopost';
|
||
$tab_export->id_parent = Tab::getIdFromClassName('AdminParentShipping');
|
||
$tab_export->module = 'chronopost';
|
||
foreach (Language::getLanguages(false) as $language)
|
||
$tab_export->name[$language['id_lang']] = 'Export Chronopost';
|
||
|
||
$tab_import = new Tab();
|
||
$tab_import->class_name = 'AdminImportChronopost';
|
||
$tab_import->id_parent = Tab::getIdFromClassName('AdminParentShipping');
|
||
$tab_import->module = 'chronopost';
|
||
foreach (Language::getLanguages(false) as $language)
|
||
$tab_import->name[$language['id_lang']] = 'Import Chronopost';
|
||
|
||
|
||
$tab_bordereau = new Tab();
|
||
$tab_bordereau->class_name = 'AdminBordereauChronopost';
|
||
$tab_bordereau->id_parent = Tab::getIdFromClassName('AdminParentShipping');
|
||
$tab_bordereau->module = 'chronopost';
|
||
foreach (Language::getLanguages(false) as $language)
|
||
$tab_bordereau->name[$language['id_lang']] = 'Bordereau de fin de journée';
|
||
|
||
return $tab_import->add() && $tab_export->add() && $tab_bordereau->add();
|
||
}
|
||
|
||
|
||
public static function checkPSVersion()
|
||
{
|
||
return ((version_compare(_PS_VERSION_, MIN_VERSION) >= 0) && (version_compare(_PS_VERSION_, MAX_VERSION) < 0));
|
||
}
|
||
|
||
|
||
public static function createChronopostCarriers($carrierConfig)
|
||
{
|
||
if (Shop::isFeatureActive())
|
||
Shop::setContext(Shop::CONTEXT_ALL);
|
||
|
||
// Create carriers from config
|
||
foreach($carrierConfig as $carrierName=>$config)
|
||
{
|
||
$carrier = new Carrier();
|
||
$carrier->name = $config['name'];
|
||
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
|
||
$carrier->url = $config['url'];
|
||
$carrier->active = $config['active'];
|
||
$carrier->deleted = $config['deleted'];
|
||
$carrier->delay = $config['delay'];
|
||
$carrier->shipping_handling = $config['shipping_handling'];
|
||
$carrier->range_behavior = $config['range_behavior'];
|
||
$carrier->is_module = $config['is_module'];
|
||
$carrier->shipping_external = $config['shipping_external'];
|
||
$carrier->external_module_name = $config['external_module_name'];
|
||
$carrier->need_range = $config['need_range'];
|
||
|
||
$languages = Language::getLanguages(true);
|
||
|
||
foreach ($languages as $language) {
|
||
if (array_key_exists($language['iso_code'], $config['delay']))
|
||
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
|
||
else
|
||
$carrier->delay[$language['id_lang']] = $config['delay']['fr'];
|
||
}
|
||
|
||
if ($carrier->add())
|
||
{
|
||
|
||
Configuration::updateValue($config['configuration_item'],(int)($carrier->id));
|
||
|
||
// ASSIGN GROUPS
|
||
$groups = Group::getgroups(true);
|
||
foreach ($groups as $group)
|
||
{
|
||
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'carrier_group VALUE (\''.(int)($carrier->id).'\',\''.(int)($group['id_group']).'\')');
|
||
}
|
||
|
||
// ASSIGN ZONES
|
||
$zones=Zone::getZones();
|
||
foreach($zones as $zone)
|
||
$carrier->addZone($zone['id_zone']);
|
||
|
||
// RANGE PRICE
|
||
$rp=new RangePrice();
|
||
$rp->id_carrier=$carrier->id;
|
||
$rp->delimiter1=0;
|
||
$rp->delimiter2=100000;
|
||
$rp->add();
|
||
|
||
|
||
$fp=fopen(_MYDIR_.'/csv/'.$carrierName.'.csv', 'r');
|
||
// insert prices per weight range
|
||
while($line=fgetcsv($fp))
|
||
{
|
||
$rangeWeight = new RangeWeight();
|
||
$rangeWeight->id_carrier = $carrier->id;
|
||
$rangeWeight->delimiter1 = $line[0];
|
||
$rangeWeight->delimiter2 = $line[1];
|
||
$rangeWeight->price_to_affect=$line[2];
|
||
$rangeWeight->add();
|
||
|
||
}
|
||
|
||
//copy logo
|
||
if (!copy(dirname(__FILE__).'/img/'.$config['logo_filename'].'.jpg',_PS_SHIP_IMG_DIR_.'/'.$carrier->id.'.jpg'))
|
||
return false;
|
||
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function uninstall()
|
||
{
|
||
$carriers=array(
|
||
Configuration::get('CHRONORELAIS_CARRIER_ID'),
|
||
Configuration::get('CHRONOPOST_CARRIER_ID'),
|
||
Configuration::get('CHRONOEXPRESS_CARRIER_ID'),
|
||
Configuration::get('CHRONO10_CARRIER_ID'),
|
||
Configuration::get('CHRONO18_CARRIER_ID'),
|
||
Configuration::get('CHRONOCLASSIC_CARRIER_ID')
|
||
);
|
||
|
||
foreach($carriers as $cid)
|
||
{
|
||
$c=new Carrier($cid);
|
||
if(Validate::isLoadedObject($c)) {
|
||
$c->deleted=true;
|
||
$c->save();
|
||
}
|
||
}
|
||
|
||
$tab = new Tab(Tab::getIdFromClassName('AdminExportChronopost'));
|
||
$tab->delete();
|
||
|
||
$tab = new Tab(Tab::getIdFromClassName('AdminImportChronopost'));
|
||
if (!$tab->delete()) return false;
|
||
|
||
$tab = new Tab(Tab::getIdFromClassName('AdminBordereauChronopost'));
|
||
if (!$tab->delete()) return false;
|
||
|
||
return parent::uninstall();
|
||
}
|
||
|
||
|
||
|
||
static public function gettingReadyForSaturday()
|
||
{
|
||
if(Configuration::get('CHRONOPOST_SATURDAY_ACTIVE')!='yes') return false;
|
||
|
||
$start=new DateTime('last sun');
|
||
// COMPAT < 5.36 : no chaining (returns NULL)
|
||
$start->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_DAY_START').' days');
|
||
$start->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_HOUR_START').' hours');
|
||
$start->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_MINUTE_START').' minutes');
|
||
$end=new DateTime('last sun');
|
||
$end->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_DAY_END').' days');
|
||
$end->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_HOUR_END').' hours');
|
||
$end->modify('+'.Configuration::get('CHRONOPOST_SATURDAY_MINUTE_END').' minutes');
|
||
|
||
|
||
if($end<$start) $end->modify('+1 week');
|
||
$now=new DateTime();
|
||
|
||
|
||
if($start<=$now && $now<=$end)
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
|
||
}
|
||
|
||
static public function isSaturdayOptionApplicable()
|
||
{
|
||
if(Configuration::get('CHRONOPOST_SATURDAY_CHECKED')!='yes') return false;
|
||
else return self::gettingReadyForSaturday();
|
||
|
||
}
|
||
|
||
static public function trackingStatus($id_order, $shipping_number)
|
||
{
|
||
// MAIL::SEND is bugged in 1.5 !
|
||
// http://forge.prestashop.com/browse/PNM-754 (Unresolved as of 2013-04-15)
|
||
// Context fix (it's that easy)
|
||
Context::getContext()->link = new Link();
|
||
// Fix context by adding employee
|
||
$cookie = new Cookie('psAdmin');
|
||
Context::getContext()->employee = new Employee($cookie->id_employee);
|
||
|
||
$o=new Order($id_order);
|
||
$o->shipping_number=$shipping_number;
|
||
$o->save();
|
||
|
||
// New in 1.5
|
||
$id_order_carrier = Db::getInstance()->getValue('
|
||
SELECT `id_order_carrier`
|
||
FROM `'._DB_PREFIX_.'order_carrier`
|
||
WHERE `id_order` = '.(int)$id_order);
|
||
|
||
|
||
$order_carrier = new OrderCarrier($id_order_carrier);
|
||
$order_carrier->tracking_number=$shipping_number;
|
||
$order_carrier->update();
|
||
// No, there is no method in Order to retrieve the orderCarrier object(s)
|
||
|
||
$history = new OrderHistory();
|
||
$history->id_order = (int)($o->id);
|
||
$history->id_order_state = _PS_OS_SHIPPING_;
|
||
$history->changeIdOrderState(_PS_OS_SHIPPING_);
|
||
$history->save();
|
||
|
||
$customer=new Customer($o->id_customer);
|
||
$carrier=new Carrier($o->id_carrier);
|
||
$tracking_url=str_replace('@', $o->shipping_number, $carrier->url);
|
||
|
||
$templateVars = array(
|
||
'{tracking_link}' => '<a href="'.$tracking_url.'">'.$o->shipping_number.'</a>',
|
||
'{tracking_code}' => $o->shipping_number,
|
||
'{firstname}' => $customer->firstname,
|
||
'{lastname}' => $customer->lastname,
|
||
'{id_order}' => (int)($o->id)
|
||
);
|
||
|
||
Mail::Send($o->id_lang, 'tracking', 'Numéro de suivi pour votre commande' , $templateVars, $customer->email,
|
||
$customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _MYDIR_.'/mails/', true);
|
||
}
|
||
|
||
|
||
public static function errorStatus($id_order)
|
||
{
|
||
/*
|
||
$history = new OrderHistory();
|
||
$history->id_order = (int)($id_order);
|
||
$history->changeIdOrderState(10, (int)($id_order)); // TODO with conf value
|
||
$history->save();
|
||
*/
|
||
}
|
||
|
||
|
||
public static function amountToInsure($id_order)
|
||
{
|
||
if(Configuration::get('CHRONOPOST_ADVALOREM_ENABLED')==0) return -1;
|
||
$order=new Order($id_order);
|
||
if($order->total_products<(float)Configuration::get('CHRONOPOST_ADVALOREM_MINVALUE')) return 0;
|
||
return $order->total_products;
|
||
}
|
||
|
||
public function hookUpdateCarrier($params)
|
||
{
|
||
if (Shop::isFeatureActive())
|
||
Shop::setContext(Shop::CONTEXT_ALL);
|
||
|
||
// Ensures that if our carrier ID changes after a modification, we still have it up-to-date
|
||
if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONORELAIS_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONORELAIS_CARRIER_ID', $params['carrier']->id);
|
||
|
||
else if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONOPOST_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONOPOST_CARRIER_ID', $params['carrier']->id);
|
||
|
||
else if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONOEXPRESS_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONOEXPRESS_CARRIER_ID', $params['carrier']->id);
|
||
|
||
else if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONO10_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONO10_CARRIER_ID', $params['carrier']->id);
|
||
|
||
else if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONO18_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONO18_CARRIER_ID', $params['carrier']->id);
|
||
else if ((int)($params['id_carrier']) == (int)(Configuration::get('CHRONOCLASSIC_CARRIER_ID')))
|
||
Configuration::updateValue('CHRONOCLASSIC_CARRIER_ID', $params['carrier']->id);
|
||
|
||
// Ensures Chrono18 and Chrono13 not selected at the same time
|
||
$c18=new Carrier(Configuration::get('CHRONO18_CARRIER_ID'));
|
||
$c13=new Carrier(Configuration::get('CHRONOPOST_CARRIER_ID'));
|
||
|
||
|
||
if (($params['carrier']->id==Configuration::get('CHRONOPOST_CARRIER_ID') && (int)$params['carrier']->active==1
|
||
&& $c18->active==1)
|
||
or ($params['carrier']->id==Configuration::get('CHRONO18_CARRIER_ID') && (int)$params['carrier']->active==1
|
||
&& $c13->active==1 )
|
||
)
|
||
{
|
||
|
||
$params['carrier']->active=0;
|
||
$params['carrier']->save();
|
||
|
||
echo "<script>alert('Vous ne pouvez pas activer Chronopost avant 13h et Chronopost avant 18h en même temps');
|
||
history.back();
|
||
</script>";
|
||
exit();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
function hookNewOrder($params)
|
||
{
|
||
// Are we dealing with Chronorelais here ?
|
||
if(Configuration::get('CHRONORELAIS_CARRIER_ID')!=$params['cart']->id_carrier) return;
|
||
|
||
include_once __DIR__.'/classes/PointRelaisServiceWSService.php';
|
||
|
||
// Update order delivery address to PR address (new in 2.8.4 per support #300)
|
||
|
||
// Data
|
||
$cart=$params['cart'];
|
||
$current_address=new Address($cart->id_address_delivery);
|
||
$relais=Db::getInstance()->getValue('SELECT id_pr FROM `'._DB_PREFIX_.'chrono_cart_relais` WHERE id_cart='.$params['cart']->id);
|
||
|
||
// Getting relais details
|
||
$ws=new PointRelaisServiceWSService();
|
||
$p=new rechercheBtAvecPFParIdChronopostA2Pas();
|
||
$p->id=$relais;
|
||
$bt=$ws->rechercheBtAvecPFParIdChronopostA2Pas($p)->return;
|
||
|
||
// Populate Address object
|
||
$a=new Address();
|
||
$a->alias='Point ChronoRelais '.$bt->identifiantChronopostPointA2PAS;
|
||
$a->id_customer=$cart->id_customer;
|
||
$a->id_country=Country::getByIso('FR');
|
||
$a->company=substr($bt->nomEnseigne,0,32);
|
||
$a->lastname=$current_address->lastname;
|
||
$a->firstname=$current_address->firstname;
|
||
$a->address1=$bt->adresse1;
|
||
$a->address2=isset($bt->adresse2)?$bt->adresse2:'';
|
||
$a->postcode=$bt->codePostal;
|
||
$a->city=$bt->localite;
|
||
$a->phone=$current_address->phone;
|
||
$a->phone_mobile=$current_address->phone_mobile;
|
||
$a->other=$bt->identifiantChronopostPointA2PAS; // ID Point Relais
|
||
$a->active=0;
|
||
$a->deleted=1;
|
||
$a->id_customer=null;
|
||
$a->id_manufacturer=null;
|
||
|
||
// Save and assign to cart
|
||
$a->save();
|
||
$params['order']->id_address_delivery = $a->id;
|
||
$params['order']->save();
|
||
|
||
return;
|
||
|
||
}
|
||
|
||
|
||
public function hookBackOfficeHeader($params)
|
||
{
|
||
return '<script>
|
||
$(document).ready(function() {
|
||
$.get("'._MODULE_DIR_.'chronopost/async/updateTracking.php");
|
||
});
|
||
</script>
|
||
';
|
||
}
|
||
|
||
public function hookHeader($params)
|
||
{
|
||
$file = basename(Tools::getValue('controller'));
|
||
if(!$file) $file = basename($_SERVER['SCRIPT_NAME'], '.php');
|
||
|
||
|
||
// check if on right page
|
||
if (!in_array($file, array('order-opc', 'order', 'orderopc'))) return;
|
||
|
||
|
||
$this->context->smarty->assign(
|
||
array(
|
||
'module_uri'=>__PS_BASE_URI__.'modules/'.$this->name
|
||
)
|
||
);
|
||
|
||
return $this->context->smarty->fetch(dirname(__FILE__).'/views/templates/hook/header.tpl');
|
||
}
|
||
|
||
public function hookTop($params)
|
||
{
|
||
|
||
// if OPC, we're done
|
||
if(Configuration::get('PS_ORDER_PROCESS_TYPE')) return;
|
||
|
||
// check page
|
||
$file = basename(Tools::getValue('controller'));
|
||
if(!$file) $file = basename($_SERVER['SCRIPT_NAME'], '.php');
|
||
|
||
// check if on right page
|
||
if (!in_array($file, array('order-opc', 'order', 'orderopc'))) return;
|
||
|
||
// check step
|
||
if($this->context->controller->step!=2) return;
|
||
|
||
$address=new Address($params['cart']->id_address_delivery);
|
||
|
||
$this->context->smarty->assign(
|
||
array(
|
||
'module_uri' =>__PS_BASE_URI__.'modules/'.$this->name,
|
||
'cust_codePostal' => $address->postcode,
|
||
'cust_firstname' => $address->firstname,
|
||
'cust_lastname' => $address->lastname,
|
||
'cartID' => $params['cart']->id,
|
||
'opc' => false,
|
||
'carrierID' => Configuration::get('CHRONORELAIS_CARRIER_ID'),
|
||
|
||
'cust_address' => $address->address1.' '.$address->address2.' '
|
||
.$address->postcode.' '.$address->city,
|
||
'cust_address_clean' => $address->address1.' '.$address->address2.' ',
|
||
'cust_city' => $address->city
|
||
)
|
||
);
|
||
|
||
return $this->context->smarty->fetch(dirname(__FILE__).'/views/templates/hook/chronorelais.tpl');
|
||
}
|
||
|
||
public function hookExtraCarrier($params)
|
||
{
|
||
|
||
// if not OPC, do nothing
|
||
if(!Configuration::get('PS_ORDER_PROCESS_TYPE')) return;
|
||
$a=new Address($this->context->cart->id_address_delivery);
|
||
$country=new Country((int)$a->id_country);
|
||
if((int)$this->context->cart->id_carrier!=Configuration::get('CHRONORELAIS_CARRIER_ID')
|
||
or $country->iso_code!='FR' and $country->iso_code!='FX')
|
||
return ; // not selected, do nothing
|
||
|
||
|
||
$this->context->smarty->assign(
|
||
array(
|
||
'module_uri' =>__PS_BASE_URI__.'modules/'.$this->name,
|
||
'cust_codePostal' => $params['address']->postcode,
|
||
'cust_firstname' => $params['address']->firstname,
|
||
'cust_lastname' => $params['address']->lastname,
|
||
'cartID' => $params['cart']->id,
|
||
'opc' => true,
|
||
'carrierID' => Configuration::get('CHRONORELAIS_CARRIER_ID'),
|
||
|
||
|
||
'cust_address_clean' => $params['address']->address1.' '.$params['address']->address2,
|
||
'cust_city' => $params['address']->city,
|
||
'cust_address' => $params['address']->address1.' '.$params['address']->address2.' '
|
||
.$params['address']->postcode.' '.$params['address']->city
|
||
)
|
||
);
|
||
|
||
|
||
return $this->context->smarty->fetch(dirname(__FILE__).'/views/templates/hook/chronorelais.tpl');
|
||
}
|
||
|
||
|
||
public static function getPointRelaisAddress($orderid)
|
||
{
|
||
$order= new Order($orderid);
|
||
include_once _MYDIR_.'/classes/PointRelaisServiceWSService.php';
|
||
|
||
if($order->id_carrier!=Configuration::get('CHRONORELAIS_CARRIER_ID')) return null;
|
||
|
||
|
||
$btid=Db::getInstance()->getRow('SELECT id_pr FROM `'._DB_PREFIX_.'chrono_cart_relais` WHERE id_cart='.$order->id_cart);
|
||
$btid=$btid['id_pr'];
|
||
|
||
// Fetch BT object
|
||
$ws=new PointRelaisServiceWSService();
|
||
|
||
$p=new rechercheBtAvecPFParIdChronopostA2Pas();
|
||
$p->id=$btid;
|
||
$bt=$ws->rechercheBtAvecPFParIdChronopostA2Pas($p)->return;
|
||
|
||
return $bt;
|
||
|
||
}
|
||
|
||
public static function minNumberOfPackages($orderid)
|
||
{
|
||
$order=new Order($orderid);
|
||
$nblt=1;
|
||
|
||
|
||
if($order->getTotalWeight()*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF')>20 && $order->id_carrier==Configuration::get('CHRONORELAIS_CARRIER_ID'))
|
||
$nblt=ceil($order->getTotalWeight()*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF')/20);
|
||
if($order->getTotalWeight()*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF')>30)
|
||
$nblt=ceil($order->getTotalWeight()*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF')/30);
|
||
|
||
return $nblt;
|
||
}
|
||
|
||
|
||
static public function isChrono($id_carrier)
|
||
{
|
||
return $id_carrier==Configuration::get('CHRONOPOST_CARRIER_ID')
|
||
|| $id_carrier==Configuration::get('CHRONORELAIS_CARRIER_ID')
|
||
|| $id_carrier==Configuration::get('CHRONOEXPRESS_CARRIER_ID')
|
||
|| $id_carrier==Configuration::get('CHRONO10_CARRIER_ID')
|
||
|| $id_carrier==Configuration::get('CHRONO18_CARRIER_ID')
|
||
|| $id_carrier==Configuration::get('CHRONOCLASSIC_CARRIER_ID');
|
||
}
|
||
|
||
public function hookAdminOrder($params)
|
||
{
|
||
$order = new Order((int)($params['id_order']));
|
||
if(
|
||
!self::isChrono($order->id_carrier)
|
||
) return '';
|
||
|
||
$r='<div class="row"><div class="panel col-lg-7">
|
||
<div class="panel-heading">
|
||
<i class="icon-truck "></i> Édition de l\'étiquette Chronopost</div>
|
||
<form method="POST" action="'.$this->_path.'/postSkybill.php" role="form" class="form-horizontal">';
|
||
|
||
|
||
|
||
if(Configuration::get('CHRONOPOST_BAL_ENABLED')==1
|
||
&& ($order->id_carrier==Configuration::get('CHRONOPOST_CARRIER_ID') or $order->id_carrier==Configuration::get('CHRONO18_CARRIER_ID'))
|
||
) $r.='<p style="text-align:center;width:400px"><b>Option BAL activée.</b></p>';
|
||
|
||
$r.='<script>
|
||
$(function() {
|
||
$.get("'._MODULE_DIR_.'/chronopost/async/nblt.php?orderid='.$params['id_order'].'", function(data) {
|
||
$("#multiOne").val(data);
|
||
});
|
||
});
|
||
</script>';
|
||
|
||
if(self::gettingReadyForSaturday()) $r.=
|
||
'<div class="form-group"><div class="col-sm-offset-4 col-sm-8">
|
||
<div class="checkbox">
|
||
<label>
|
||
<input type="checkbox" id="shipSaturday" name="shipSaturday" value="yes" '
|
||
.(self::isSaturdayOptionApplicable()?' checked':'').'/> '.$this->l('Option livraison le samedi').'
|
||
</label>
|
||
</div>
|
||
</div></div>';
|
||
|
||
$r.='<div class="form-group"><label for="multiOne" class="control-label col-sm-4">'.$this->l('Nombre de colis').'</label>'
|
||
.'<div class="col-sm-8"><input type="number" name="multiOne" id="multiOne" value="1" class="form-control"/></div>'
|
||
.'</div>';
|
||
|
||
// AD VALOREM
|
||
$toInsure=self::amountToInsure($params['id_order']);
|
||
if($toInsure>-1)
|
||
{
|
||
|
||
$r.='<div class="form-group"><div class="col-sm-offset-4 col-sm-8">
|
||
<div class="checkbox">
|
||
<label>
|
||
<input type="checkbox" id="advalorem" name="advalorem" value="yes" '
|
||
.($toInsure>0?' checked':'').'/> '.$this->l('Assurance Ad Valorem').'
|
||
</label>
|
||
</div>
|
||
</div></div>';
|
||
|
||
$r.='<div class="form-group"><label for="advalorem_value" class="control-label col-sm-4">'.$this->l('Montant assuré').'</label>'
|
||
.'<div class="col-sm-8"><input class="form-control" type="text" id="advalorem_value" name="advalorem_value" value="'.$toInsure.'"/></div>'
|
||
.'</div>';
|
||
|
||
}
|
||
|
||
|
||
|
||
$r.= '<input type="hidden" name="orderid" value="'
|
||
.$params['id_order'].'"/><p style="text-align:center">'
|
||
.'<input type="hidden" name="shared_secret" value="'.Configuration::get('CHRONOPOST_SECRET').'"/><input class="btn btn-primary" type="submit" value="Editer l\'étiquette d\'expédition" class="button" style="margin:10px;"/>';
|
||
if($order->id_carrier!=Configuration::get('CHRONOEXPRESS_CARRIER_ID')
|
||
&& $order->id_carrier!=Configuration::get('CHRONOCLASSIC_CARRIER_ID'))
|
||
{
|
||
$r.='<input class="btn btn-default" style="margin:10px;" type="submit" name="return" value="Editer l\'étiquette de retour" class="button"/>';
|
||
}
|
||
$r.='</form></div></div>';
|
||
return $r;
|
||
}
|
||
|
||
|
||
public static function calculateProducts($cart)
|
||
{
|
||
$a=new Address($cart->id_address_delivery);
|
||
$c=new Country($a->id_country);
|
||
|
||
$res=array('chrono10'=>false, 'chronoclassic'=>false, 'chrono18'=>false);
|
||
|
||
$cache=Db::getInstance()->executeS('SELECT chrono10, chrono18, chronoclassic, last_updated FROM `'._DB_PREFIX_.'chrono_calculateproducts_cache2` WHERE postcode="'.$a->postcode.'" AND country="'.$c->iso_code.'"');
|
||
|
||
if(empty($cache) || $cache[0]['last_updated']+24*3600<time())
|
||
{
|
||
// QUICKCOST & CALCULATE PRODUCTS
|
||
include_once(_MYDIR_.'/classes/QuickcostServiceWSService.php');
|
||
|
||
$ws=new QuickcostServiceWSService();
|
||
$cp=new calculateProducts();
|
||
|
||
$cp->accountNumber=Configuration::get('CHRONOPOST_GENERAL_ACCOUNT');
|
||
$cp->password=Configuration::get('CHRONOPOST_GENERAL_PASSWORD');
|
||
$cp->depZipCode=Configuration::get('CHRONOPOST_SHIPPER_ZIPCODE');
|
||
$cp->depCountryCode='FR';
|
||
$cp->weight=$cart->getTotalWeight()*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF');
|
||
$cp->arrCountryCode=$c->iso_code;
|
||
$cp->arrZipCode=$a->postcode;
|
||
$cp->type='M';
|
||
|
||
try {
|
||
$cpres=$ws->calculateProducts($cp);
|
||
} catch(Exception $e)
|
||
{
|
||
return $res;
|
||
}
|
||
|
||
if(empty($cpres->return->productList)) return $res;
|
||
|
||
foreach($cpres->return->productList as $product)
|
||
{
|
||
if($product->productCode==2)
|
||
{
|
||
$res['chrono10']=true;
|
||
}
|
||
if($product->productCode==16)
|
||
{
|
||
$res['chrono18']=true;
|
||
}
|
||
if($product->productCode==44)
|
||
{
|
||
$res['chronoclassic']=true;
|
||
}
|
||
}
|
||
|
||
// INSERT cache
|
||
if(empty($cache))
|
||
{
|
||
$sql='INSERT INTO `'._DB_PREFIX_.'chrono_calculateproducts_cache2`
|
||
(`postcode`,`country`, `chrono10`,`chrono18`, `chronoclassic`,`last_updated`) VALUES
|
||
("'.$a->postcode.'", "'.$c->iso_code.'", '.($res['chrono10']==true?1:0).', '.($res['chrono18']==true?1:0).',
|
||
'.($res['chronoclassic']==true?1:0).', '.time().')';
|
||
Db::getInstance()->Execute($sql);
|
||
}
|
||
else // UPDATE cache
|
||
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'chrono_calculateproducts_cache2`
|
||
SET `chrono10`='.($res['chrono10']==true?1:0).', `chrono18`='.($res['chrono18']==true?1:0).',
|
||
`chronoclassic`='.($res['chronoclassic']==true?1:0).',
|
||
`last_updated`='.time().' WHERE postcode="'.$a->postcode.'" AND country="'.$c->iso_code.'"');
|
||
} else {
|
||
$res['chrono10']=$cache[0]['chrono10'];
|
||
$res['chrono18']=$cache[0]['chrono18'];
|
||
$res['chronoclassic']=$cache[0]['chronoclassic'];
|
||
}
|
||
|
||
return $res;
|
||
}
|
||
|
||
|
||
/** CARRIER-RELATED FUNCTIONS **/
|
||
public function getOrderShippingCost($cart,$shipping_cost)
|
||
{
|
||
$productCode=1;
|
||
$classicAvailable=true;
|
||
$relaisAvailable=true;
|
||
if($cart->id_address_delivery==0) return $shipping_cost; // CASE NOT LOGGED IN
|
||
|
||
$a=new Address($cart->id_address_delivery);
|
||
$c=new Country($a->id_country);
|
||
|
||
foreach($cart->getProducts() as $p)
|
||
{
|
||
// check if no product > 20 kg
|
||
if($p['weight']*Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 20)
|
||
{
|
||
$relaisAvailable=false;
|
||
}
|
||
if($p['weight'] *Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF') > 30) { $classicAvailable=false; break; }
|
||
}
|
||
|
||
|
||
|
||
if(!$classicAvailable) return false;
|
||
;
|
||
// CALCULATE PRODUCTS
|
||
if($this->id_carrier==Configuration::get('CHRONO10_CARRIER_ID') or $this->id_carrier==Configuration::get('CHRONOCLASSIC_CARRIER_ID') or $this->id_carrier==Configuration::get('CHRONO18_CARRIER_ID'))
|
||
$calculatedProducts=self::calculateProducts($cart);
|
||
|
||
switch($this->id_carrier)
|
||
{
|
||
case Configuration::get('CHRONORELAIS_CARRIER_ID'):
|
||
$productCode=self::$productCodes['CHRONORELAIS_CARRIER_ID'];
|
||
if($c->iso_code!='FR' && $c->iso_code!='FX') {
|
||
return false;
|
||
}
|
||
if(!$relaisAvailable) return false;
|
||
break;
|
||
|
||
|
||
case Configuration::get('CHRONOPOST_CARRIER_ID'):
|
||
$productCode=self::$productCodes['CHRONOPOST_CARRIER_ID'];
|
||
if($c->iso_code!='FR' && $c->iso_code!='FX') return false;
|
||
|
||
break;
|
||
|
||
case Configuration::get('CHRONO10_CARRIER_ID'):
|
||
if($calculatedProducts['chrono10']==false) return false;
|
||
$productCode=self::$productCodes['CHRONO10_CARRIER_ID'];
|
||
break;
|
||
|
||
case Configuration::get('CHRONO18_CARRIER_ID'):
|
||
if($c->iso_code!='FR' && $c->iso_code!='FX') return false;
|
||
if($calculatedProducts['chrono18']==false) return false;
|
||
$productCode=self::$productCodes['CHRONO18_CARRIER_ID'];
|
||
break;
|
||
|
||
case Configuration::get('CHRONOEXPRESS_CARRIER_ID'):
|
||
if($c->iso_code=='FR' or $c->iso_code=='FX') return false;
|
||
$productCode=self::$productCodes['CHRONOEXPRESS_CARRIER_ID'];
|
||
break;
|
||
|
||
case Configuration::get('CHRONOCLASSIC_CARRIER_ID'):
|
||
if($calculatedProducts['chronoclassic']==false) return false;
|
||
$productCode=self::$productCodes['CHRONOCLASSIC_CARRIER_ID'];
|
||
break;
|
||
}
|
||
|
||
|
||
|
||
|
||
if(Configuration::get('CHRONOPOST_QUICKCOST_ENABLED')==0)
|
||
{
|
||
|
||
if($c->iso_code=='FR' && $a->postcode>=20000 && $a->postcode <21000)
|
||
{
|
||
return $shipping_cost+(float)Configuration::get('CHRONOPOST_CORSICA_SUPPLEMENT');
|
||
}
|
||
|
||
// Let's just use Prestashop's native calculations
|
||
return $shipping_cost;
|
||
}
|
||
|
||
|
||
include_once(_MYDIR_.'/classes/QuickcostServiceWSService.php');
|
||
$ws=new QuickcostServiceWSService();
|
||
$qc=new quickCost();
|
||
$qc->accountNumber=Configuration::get('CHRONOPOST_GENERAL_ACCOUNT');
|
||
$qc->password=Configuration::get('CHRONOPOST_GENERAL_PASSWORD');
|
||
$qc->depCode=Configuration::get('CHRONOPOST_SHIPPER_ZIPCODE');
|
||
$qc->arrCode=(($c->iso_code=='FR'||$c->iso_code=='FX')?$a->postcode:$c->iso_code);
|
||
$qc->weight=$cart->getTotalWeight();
|
||
if($qc->weight==0) $qc->weight=0.1; // 0 yeilds an error
|
||
|
||
$qc->productCode=$productCode;
|
||
|
||
|
||
$qc->type='M';
|
||
|
||
try {
|
||
$res=$ws->quickCost($qc);
|
||
|
||
} catch(Exception $e)
|
||
{
|
||
return $shipping_cost;
|
||
}
|
||
|
||
|
||
if($res->return->amount!=0)
|
||
{
|
||
return $res->return->amount;
|
||
}
|
||
|
||
return $shipping_cost;
|
||
|
||
}
|
||
|
||
|
||
|
||
public function getOrderShippingCostExternal($params){
|
||
return $this->getOrderShippingCost($params, 0);
|
||
}
|
||
|
||
|
||
|
||
|
||
/** ADMINISTRATION **/
|
||
private function _generateChronoForm($prefix)
|
||
{
|
||
$prefix=Tools::strtolower($prefix);
|
||
$var_name=Tools::strtoupper($prefix);
|
||
|
||
$output='<label>'.$this->l('Civilité').'</label>
|
||
<div class="margin-form"><select name="chronoparams['.$prefix.'][civility]">
|
||
<option value="M"'.(Configuration::get('CHRONOPOST_'.$var_name.'_CIVILITY')=='M'?' selected':'').'>Monsieur</option>
|
||
<option value="E"'.(Configuration::get('CHRONOPOST_'.$var_name.'_CIVILITY')=='E'?' selected':'').'>Madame</option>
|
||
<option value="L"'.(Configuration::get('CHRONOPOST_'.$var_name.'_CIVILITY')=='L'?' selected':'').'>Mademoiselle
|
||
</option></select></div>
|
||
<label>'.$this->l('Raison sociale').'</label><div class="margin-form">
|
||
<input type="text" maxlength="35" name="chronoparams['.$prefix.'][name]"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_NAME').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Raison sociale 2').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][name2]" maxlength="35"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_NAME2').'"/>
|
||
<p class="clear hint"> '.$this->l('Optionnel').'</p>
|
||
</div>
|
||
|
||
<label>'.$this->l('Adresse').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][address]" maxlength="35"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_ADDRESS').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Adresse 2').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][address2]" maxlength="35"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_ADDRESS2').'"/>
|
||
<p class="clear hint"> '.$this->l('Optionnel').'</p>
|
||
</div>
|
||
|
||
<label>'.$this->l('Code postal').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][zipcode]" maxlength="5"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_ZIPCODE').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Localite').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][city]" maxlength="30"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_CITY').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Nom et prenom du contact').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][contactname]" maxlength="35"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_CONTACTNAME').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Email').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][email]" maxlength="35"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_EMAIL').'"/>
|
||
<p class="clear hint"> '.$this->l('Optionnel').'</p>
|
||
</div>
|
||
|
||
<label>'.$this->l('Numéro de téléphone').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][phone]" maxlength="10"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_PHONE').'"/>
|
||
<p class="clear hint"> '.$this->l('Optionnel').'</p>
|
||
</div>
|
||
|
||
<label>'.$this->l('Numéro de mobile').'</label><div class="margin-form">
|
||
<input type="text" name="chronoparams['.$prefix.'][mobile]" maxlength="10"
|
||
value="'.Configuration::get('CHRONOPOST_'.$var_name.'_MOBILE').'"/>
|
||
<p class="clear hint"> '.$this->l('Optionnel').'</p>
|
||
</div>
|
||
';
|
||
|
||
return $output;
|
||
|
||
}
|
||
|
||
private function _dayField($fieldName, $default)
|
||
{
|
||
$selected=Configuration::get('CHRONOPOST_SATURDAY_'.Tools::strtoupper($fieldName));
|
||
if($selected===false) $selected=$default;
|
||
|
||
return '<select name="chronoparams[saturday]['.$fieldName.']">
|
||
<option value="1"'.(($selected==1)?' selected':'').'>Lundi</option>
|
||
<option value="2"'.(($selected==2)?' selected':'').'>Mardi</option>
|
||
<option value="3"'.(($selected==3)?' selected':'').'>Mercredi</option>
|
||
<option value="4"'.(($selected==4)?' selected':'').'>Jeudi</option>
|
||
<option value="5"'.(($selected==5)?' selected':'').'>Vendredi</option>
|
||
<option value="6"'.(($selected==6)?' selected':'').'>Samedi</option>
|
||
<option value="0"'.(($selected==0)?' selected':'').'>Dimanche</option></select>';
|
||
|
||
|
||
}
|
||
|
||
private function _hourField($fieldName, $default)
|
||
{
|
||
$selected=Configuration::get('CHRONOPOST_SATURDAY_'.Tools::strtoupper($fieldName));
|
||
if($selected===false) $selected=$default;
|
||
|
||
$r='<select name="chronoparams[saturday]['.$fieldName.']">';
|
||
for($i=0;$i<24;$i++)
|
||
{
|
||
$r.='<option value="'.$i.'"'.(($selected==$i)?' selected':'').'>'.sprintf('%02d', $i).'</option>';
|
||
}
|
||
|
||
return $r.'</select>';
|
||
|
||
}
|
||
|
||
|
||
private function _minuteField($fieldName, $default=0)
|
||
{
|
||
$selected=Configuration::get('CHRONOPOST_SATURDAY_'.Tools::strtoupper($fieldName));
|
||
if($selected===false) $selected=$default;
|
||
|
||
$r='<select name="chronoparams[saturday]['.$fieldName.']">';
|
||
for($i=0;$i<60;$i++)
|
||
{
|
||
$r.='<option value="'.$i.'"'.(($selected==$i)?' selected':'').'>'.sprintf('%02d', $i).'</option>';
|
||
}
|
||
return $r.'</select>';
|
||
|
||
}
|
||
|
||
private function _postValidation()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
private function _postProcess()
|
||
{
|
||
if (Shop::isFeatureActive())
|
||
Shop::setContext(Shop::CONTEXT_ALL);
|
||
|
||
foreach(Tools::getValue('chronoparams') as $prefix=>$var)
|
||
{
|
||
foreach($var as $varname=>$value)
|
||
{
|
||
Configuration::updateValue('CHRONOPOST_'.Tools::strtoupper($prefix).'_'.Tools::strtoupper($varname), $value);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function getContent()
|
||
{
|
||
$html = '<h2>'.$this->displayName.'</h2>';
|
||
if (Tools::isSubmit('submitchronoRelaisConfig'))
|
||
{
|
||
if($this->_postValidation() && $this->_postProcess())
|
||
{
|
||
$html .= '<div class="conf confirm">'.$this->l('Paramètres mis à jour avec succès.').'</div>';
|
||
}
|
||
}
|
||
return $html.$this->displayForm();
|
||
}
|
||
|
||
public function displayForm()
|
||
{
|
||
|
||
$printMode=array(
|
||
'PDF'=>'Format PDF',
|
||
//'THE'=>'Imprimante thermique',
|
||
'SPD'=>'Format PDF sans preuve de dépôt'
|
||
//'SER'=>'Imprimante thermique Chronopost'
|
||
);
|
||
|
||
$unitCoef=array(
|
||
'KG'=>"1",
|
||
'G'=>"0.001"
|
||
);
|
||
|
||
$output='<style>label { width:300px;}</style>
|
||
<script>
|
||
|
||
$(function() {
|
||
|
||
$("#testWSLogin").on("click", function(e)
|
||
{
|
||
e.preventDefault();
|
||
$.get("'._MODULE_DIR_.'/chronopost/async/testLogin.php?account="+$("#chrono_account").val()+"&shared_secret='.Configuration::get('CHRONOPOST_SECRET').'&password="+$("#chrono_password").val(), function(data) {
|
||
if(data=="OK") alert("Les identifiants fournis sont valides !");
|
||
else alert(data);
|
||
});
|
||
return false;
|
||
});
|
||
|
||
|
||
});
|
||
</script>
|
||
|
||
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
|
||
|
||
<!--GENERAL-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Général').'</legend>
|
||
<label>'.$this->l('N° de compte Chronopost').'</label>
|
||
<div class="margin-form">
|
||
<input id="chrono_account" type="text" name="chronoparams[general][account]" value="'.Configuration::get('CHRONOPOST_GENERAL_ACCOUNT').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Sous-compte').'</label>
|
||
<div class="margin-form">
|
||
<input id="chrono_subaccount" type="text" name="chronoparams[general][subaccount]" value="'.Configuration::get('CHRONOPOST_GENERAL_SUBACCOUNT').'"/>
|
||
</div>
|
||
|
||
<label>'.$this->l('Mot de passe Chronopost').'</label>
|
||
<div class="margin-form">
|
||
<input id="chrono_password" type="text" name="chronoparams[general][password]" value="'.Configuration::get('CHRONOPOST_GENERAL_PASSWORD').'"/>
|
||
</div>
|
||
|
||
|
||
<div class="margin-form">
|
||
<button id="testWSLogin">Tester la validité des identifiants</button>
|
||
</div>
|
||
|
||
|
||
<label>'.$this->l('Format des étiquettes').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[general][printmode]">';
|
||
|
||
foreach($printMode as $k=>$v)
|
||
$output.='<option value="'.$k.'"'
|
||
.($k==Configuration::get('CHRONOPOST_GENERAL_PRINTMODE')?' selected':'')
|
||
.'>'.$v.'</option>';
|
||
$output.='</select></div>';
|
||
|
||
$output.='<label>'.$this->l('Unité de poids des produits').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[general][weightcoef]"/>';
|
||
foreach($unitCoef as $k=>$v)
|
||
$output.='<option value="'.$v.'"'
|
||
.($v==Configuration::get('CHRONOPOST_GENERAL_WEIGHTCOEF')?' selected':'')
|
||
.'>'.$k.'</option>';
|
||
$output.='</select>
|
||
</div>
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
|
||
<!--SATURDAY-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Livraison le samedi').'</legend>
|
||
<label>'.$this->l('Activer l\'option "livraison le samedi"').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[saturday][active]">
|
||
<option value="yes" '.(Configuration::get('CHRONOPOST_SATURDAY_ACTIVE')=='yes'?' selected':'').'>Oui</option>
|
||
<option value="no" '.(Configuration::get('CHRONOPOST_SATURDAY_ACTIVE')!='yes'?' selected':'').'>Non</option>
|
||
</select>
|
||
</div>
|
||
<label>'.$this->l('Option cochée par défaut').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[saturday][checked]">
|
||
<option value="yes" '.(Configuration::get('CHRONOPOST_SATURDAY_CHECKED')=='yes'?' selected':'').'>Oui</option>
|
||
<option value="no" '.(Configuration::get('CHRONOPOST_SATURDAY_CHECKED')!='yes'?' selected':'').'>Non</option>
|
||
</select>
|
||
</div>
|
||
<div class="path_bar">Afficher l\'option de livraison le samedi à partir de : </div>
|
||
|
||
<label>'.$this->l('Jour').'</label>
|
||
<div class="margin-form">
|
||
'.$this->_dayField('day_start', 4).'
|
||
</div>
|
||
|
||
<label>'.$this->l('Heure').'</label>
|
||
<div class="margin-form">
|
||
'.$this->_hourField('hour_start', 18).' : '.$this->_minuteField('minute_start').'
|
||
</div>
|
||
<div class="path_bar">Jusqu\'à :</div>
|
||
<label>'.$this->l('Jour').'</label>
|
||
<div class="margin-form">
|
||
'.$this->_dayField('day_end', 5).'
|
||
</div>
|
||
<label>'.$this->l('Heure').'</label>
|
||
<div class="margin-form">
|
||
'.$this->_hourField('hour_end', 16).' : '.$this->_minuteField('minute_end').'
|
||
</div>
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
<!--CORSICA-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Livraisons vers la Corse').'</legend>
|
||
|
||
<label>'.$this->l('Supplément pour les livraisons vers la Corse').'</label>
|
||
<div class="margin-form">
|
||
|
||
+ <input name="chronoparams[corsica][supplement]" type="text" style="width:40px;text-align:right;"
|
||
value="'.(Configuration::get('CHRONOPOST_CORSICA_SUPPLEMENT')).'"/> €
|
||
<p class="clear hint">Montant paramétrable selon votre politique tarifaire. Le montant facturé par Chronopost correspond cependant aux conditions tarifaires indiquées dans votre contrat Chronopost.</p>
|
||
</div>
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
<!--QUICKCOST-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Tarification Quickcost').'</legend>
|
||
|
||
<label>'.$this->l('Activer le Quickcost').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[quickcost][enabled]">
|
||
<option value="0" '.(Configuration::get('CHRONOPOST_QUICKCOST_ENABLED')!=1?' selected':'').'>NON</option>
|
||
<option value="1" '.(Configuration::get('CHRONOPOST_QUICKCOST_ENABLED')==1?' selected':'').'>OUI</option>
|
||
</select>
|
||
<p class="clear hint">Le Quickcost permet de calculer le coût d’un envoi, en fonction des tarifs négociés avec Chronopost. Cette option remplace l’utilisation de la grille tarifaire..</p>
|
||
</div>
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
|
||
|
||
<!--AD VALOREM-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Assurance Ad-Valorem').'</legend>
|
||
|
||
<label>'.$this->l('Activer l\'Ad-Valorem').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[advalorem][enabled]">
|
||
<option value="1">OUI</option>
|
||
<option value="0"';
|
||
if(Configuration::get('CHRONOPOST_ADVALOREM_ENABLED')==0) $output.=" selected";
|
||
$output.='>NON</option>
|
||
</select>
|
||
</div>
|
||
|
||
<label>'.$this->l('Montant minimum à assurer').'</label>
|
||
<div class="margin-form">
|
||
<input type="text" name="chronoparams[advalorem][minvalue]" value="'
|
||
.Configuration::get('CHRONOPOST_ADVALOREM_MINVALUE').'"/>
|
||
<p class="clear hint">En activant cette option, pour chaque colis dépassant le montant que vous renseignez, votre envoi sera assuré à hauteur du montant des articles de ce dernier (maximum 20 000€). Vous pouvez renseigner le montant à assurer dans Vos fiche de commandes.</p>
|
||
|
||
</div>
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
<!-- BAL OPTION -->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Option BAL').'</legend>
|
||
|
||
<label>'.$this->l('Activer l\'option BAL').'</label>
|
||
<div class="margin-form">
|
||
<select name="chronoparams[bal][enabled]">
|
||
<option value="0">NON</option>
|
||
<option value="1"';
|
||
if(Configuration::get('CHRONOPOST_BAL_ENABLED')==1) $output.=" selected";
|
||
$output.='>OUI</option>
|
||
</select>
|
||
|
||
|
||
<p class="clear hint">Attention : cette option doit figurer dans votre contrat.</p>
|
||
|
||
|
||
</div>
|
||
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
|
||
<!--SHIPPER-->
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Informations expéditeur').'</legend>';
|
||
$output.=$this->_generateChronoForm('shipper');
|
||
$output.='
|
||
</fieldset>
|
||
<p class="clear"> </p>
|
||
<fieldset>
|
||
<legend><img src="../img/admin/asterisk.gif" alt="" title="" />'.$this->l('Informations du compte client').'</legend>';
|
||
$output.=$this->_generateChronoForm('customer');
|
||
$output.='
|
||
</fieldset>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="clear"> </p>
|
||
<center><input type="submit" name="submitchronoRelaisConfig" value="'.$this->l('Sauvegarder les paramètres').'" class="button" /></center>
|
||
<br/>
|
||
</form>';
|
||
|
||
return $output;
|
||
}
|
||
}
|
||
|
||
?>
|