toutpratique/modules/soflexibilite/classes/SoFlexibiliteCarrier.php
2017-02-01 07:39:20 -08:00

208 lines
8.1 KiB
PHP

<?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 soflexibilite
* @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
*/
class SoFlexibiliteCarrier extends Carrier
{
const TEXT_DOM = 'Colissimo Domicile - sans signature';
const TEXT_DOS = 'Colissimo Domicile - avec signature';
const TEXT_BPR = 'Colissimo - &Agrave; La Poste';
const TEXT_A2P = 'Colissimo - En relais PickUp ou en consigne PickUp Station';
public $mode;
protected static $carrier_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
);
public function __construct($id = null, $id_lang = null)
{
parent::__construct($id, $id_lang);
}
public function add($autodate = true, $null_values = false)
{
if (parent::add($autodate, $null_values)) {
if (version_compare(_PS_VERSION_, '1.5', '>=') && Feature::isFeatureActive()) {
Configuration::updateGlobalValue('SOFLEXIBILITE_'.$this->mode.'_ID', (int)$this->id, false);
} else {
Configuration::updateValue('SOFLEXIBILITE_'.$this->mode.'_ID', (int)$this->id);
}
return true;
}
return false;
}
public function setColissimoConfiguration($active)
{
foreach (self::$carrier_config as $k => $v) {
$this->{$k} = $v;
}
$this->name .= $this->getNameExtension();
$this->active = (int)$active;
$this->setColissimoDelay();
}
private function setColissimoDelay()
{
foreach (Language::getLanguages(false) as $language) {
if ($language['iso_code'] == 'fr') {
switch ($this->mode) {
case 'DOM':
case 'DOS':
$this->delay[$language['id_lang']] = 'Faites vous livrer à une adresse de votre choix, '.
($this->mode === 'DOM' ? 'sans' : 'avec').' signature';
break;
case 'BPR':
$this->delay[$language['id_lang']] = 'Faites vous livrer dans un des bureaux de poste parmi '.
'10 000 points de retrait partout en France';
break;
case 'A2P':
$this->delay[$language['id_lang']] = 'Faites vous livrer dans un des relais pickup ou '.
'consignes Pickup Station parmi 8 000 points de retrait partout en France';
break;
default:
$this->delay[$language['id_lang']] = 'Faites vous livrer en France selon votre choix';
break;
}
} else {
switch ($this->mode) {
case 'DOM':
case 'DOS':
$this->delay[$language['id_lang']] = 'Get delivered at home, in France '.
($this->mode === 'DOM' ? 'with' : 'without').' signature';
break;
case 'BPR':
$this->delay[$language['id_lang']] = 'Get delivered among one of our 10 000 post-offices '.
'everywhere in France';
break;
case 'A2P':
$this->delay[$language['id_lang']] = 'Get delivered in one of our relay pickup or '.
'Pickup Station among 8 000 relay everywhere in France';
break;
default:
$this->delay[$language['id_lang']] = 'Get delivered in France according to your choice';
break;
}
}
}
}
private function getNameExtension()
{
$name_extension = null;
switch ($this->mode) {
case 'DOM':
$name_extension = self::TEXT_DOM;
break;
case 'DOS':
$name_extension = self::TEXT_DOS;
break;
case 'BPR':
$name_extension = self::TEXT_BPR;
break;
case 'A2P':
$name_extension = self::TEXT_A2P;
break;
}
return html_entity_decode($name_extension, ENT_COMPAT, 'UTF-8');
}
public static function getSoColissimoCarriers(Context $context)
{
$ps15x = version_compare(_PS_VERSION_, '1.5', '>=');
$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)$context->language->id.'
)
WHERE c.`deleted` = 0
AND c.`external_module_name` = "soflexibilite"
GROUP BY c.`id_carrier`';
if ($ps15x) {
$sql .= '
ORDER BY c.`position` ASC';
}
$carriers = Db::getInstance()->executeS($sql);
if (!is_array($carriers)) {
$carriers = array();
ConfigureMessage::error(
'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)$context->employee->id
).'&id_carrier='.(int)$carriers[$key]['id_carrier'];
} elseif ($ps15x) {
$carriers[$key]['conf_url'] = '?controller=AdminCarriers&id_carrier='.
(int)$carriers[$key]['id_carrier'].'&updatecarrier&token='.
Tools::getAdminToken(
'AdminCarriers'.(int)Tab::getIdFromClassName('AdminCarriers').
(int)$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)$context->employee->id
);
}
}
}
return ($carriers);
}
}