* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7611 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class Socolissimo extends CarrierModule { private $_html = ''; private $_postErrors = array(); private $url = ''; public $_errors = array(); public $errorMessage = array(); private $_config = array( 'name' => 'La Poste - So Colissimo', 'id_tax_rules_group' => 0, 'url' => 'http://www.colissimo.fr/portail_colissimo/suivreResultat.do?parcelnumber=@', 'active' => true, 'deleted' => 0, 'shipping_handling' => false, 'range_behavior' => 0, 'is_module' => true, 'delay' => array('fr'=>'Avec La Poste, Faites-vous livrer là où vous le souhaitez en France Métropolitaine.', 'en'=>'Do you deliver wherever you want in France.'), 'id_zone' => 1, 'shipping_external'=> true, 'external_module_name'=> 'socolissimo', 'need_range' => true ); function __construct() { global $cookie; $this->name = 'socolissimo'; $this->tab = 'shipping_logistics'; $this->version = '2.0'; $this->author = 'PrestaShop'; $this->limited_countries = array('fr'); parent::__construct (); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('So Colissimo'); $this->description = $this->l('Offer your customers, different delivery methods with LaPoste.'); $this->url = Tools::getProtocol().htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/validation.php'; if (self::isInstalled($this->name)) { $ids = array(); $warning = array(); $soCarrier = new Carrier(Configuration::get('SOCOLISSIMO_CARRIER_ID')); if (Validate::isLoadedObject($soCarrier)) { if (!$this->checkZone((int)($soCarrier->id))) $warning[] .= $this->l('\'Carrier Zone(s)\'').' '; if (!$this->checkGroup((int)($soCarrier->id))) $warning[] .= $this->l('\'Carrier Group\'').' '; if (!$this->checkRange((int)($soCarrier->id))) $warning[] .= $this->l('\'Carrier Range(s)\'').' '; if (!$this->checkDelivery((int)($soCarrier->id))) $warning[] .= $this->l('\'Carrier price delivery\'').' '; } //Check config and display warning if (!Configuration::get('SOCOLISSIMO_ID')) $warning[] .= $this->l('\'Id FO\'').' '; if (!Configuration::get('SOCOLISSIMO_KEY')) $warning[] .= $this->l('\'Key\'').' '; if (!Configuration::get('SOCOLISSIMO_URL')) $warning[] .= $this->l('\'Url So\'').' '; if (count($warning)) $this->warning .= implode(' , ',$warning).$this->l('must be configured to use this module correctly').' '; } $this->errorMessage = array('998' => $this->l('Invalid key'), '999' => $this->l('Error occurred during shipping step.'), '001' => $this->l('Login FO missing'), '002' => $this->l('Login FO incorrect'), '003' => $this->l('Customer unauthorized'),'004' => $this->l('Required field missing'), '006' => $this->l('Missing signature'), '007' => $this->l('Invalid signature'), '008' => $this->l('Invalid Zip/ Postal code'), '009' => $this->l('Incorrect url format return validation.'), '010' => $this->l('Incorrect url format return error.'), '011' => $this->l('Invalid transaction ID.'), '012' => $this->l('Format incorrect shipping costs.'), '015' => $this->l('Socolissimo server unavailable.'), '016' => $this->l('Socolissimo server unavailable.'), '004' => $this->l('Required field missing'), '004' => $this->l('Required field missing')); } public function install() { global $cookie; if (!parent::install() OR !Configuration::updateValue('SOCOLISSIMO_ID', NULL) OR !Configuration::updateValue('SOCOLISSIMO_KEY', NULL) OR !Configuration::updateValue('SOCOLISSIMO_URL', 'https://ws.colissimo.fr/pudo-fo/storeCall.do') OR !Configuration::updateValue('SOCOLISSIMO_PREPARATION_TIME', 1) OR !Configuration::updateValue('SOCOLISSIMO_OVERCOST', 3.6) OR !$this->registerHook('extraCarrier') OR !$this->registerHook('AdminOrder') OR !$this->registerHook('updateCarrier') OR !$this->registerHook('newOrder') OR !Configuration::updateValue('SOCOLISSIMO_SUP_URL', 'http://ws.colissimo.fr/supervision-pudo/supervision.jsp') OR !Configuration::updateValue('SOCOLISSIMO_SUP', true)) return false; //creat config table in database $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, `cephonenumber` varchar(10) 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, PRIMARY KEY (`id_cart`,`id_customer`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'; if (!Db::getInstance()->Execute($sql)) return false; //add carrier in back office if (!$this->createSoColissimoCarrier($this->_config)) return false; return true; } public function uninstall() { global $cookie; $so_id = (int)Configuration::get('SOCOLISSIMO_CARRIER_ID'); if (!parent::uninstall() OR !Db::getInstance()->Execute('DROP TABLE IF EXISTS`'._DB_PREFIX_.'socolissimo_delivery_info`') OR !$this->unregisterHook('extraCarrier') OR !$this->unregisterHook('payment') OR !$this->unregisterHook('AdminOrder') OR !$this->unregisterHook('newOrder') OR !$this->unregisterHook('updateCarrier') OR !Configuration::deleteByName('SOCOLISSIMO_ID') OR !Configuration::deleteByName('SOCOLISSIMO_KEY') OR !Configuration::deleteByName('SOCOLISSIMO_URL') OR !Configuration::deleteByName('SOCOLISSIMO_OVERCOST') OR !Configuration::deleteByName('SOCOLISSIMO_PREPARATION_TIME') OR !Configuration::deleteByName('SOCOLISSIMO_CARRIER_ID') OR !Configuration::deleteByName('SOCOLISSIMO_SUP') OR !Configuration::deleteByName('SOCOLISSIMO_SUP_URL') OR !Configuration::deleteByName('SOCOLISSIMO_OVERCOST_TAX')) return false; //Delete So Carrier $soCarrier = new Carrier($so_id); //if socolissimo carrier is default set other one as default if (Configuration::get('PS_CARRIER_DEFAULT') == (int)($soCarrier->id)) { $carriersD = Carrier::getCarriers((int)($cookie->id_lang)); foreach($carriersD as $carrierD) if ($carrierD['active'] AND !$carrierD['deleted'] AND ($carrierD['name'] != $this->_config['name'])) Configuration::updateValue('PS_CARRIER_DEFAULT', $carrierD['id_carrier']); } //save old carrier id Configuration::updateValue('SOCOLISSIMO_CARRIER_ID_HIST', Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST').'|'.(int)($soCarrier->id)); $soCarrier->deleted = 1; if (!$soCarrier->update()) return false; return true; } public function getContent() { $this->_html .= '

' . $this->l('So Colissimo').'

'; if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) $this->_html .= '
nok '.$this->l('So Colissimo isn\'t compliant with One Page Checkout feature, in order to use this module, please activate the standard order process (Preferences > "Order process type")').'
'; if (!empty($_POST) AND Tools::isSubmit('submitSave')) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else foreach ($this->_postErrors AS $err) $this->_html .= '
nok '.$err.'
'; } $this->_displayForm(); return $this->_html; } private function _displayForm() { global $cookie; $this->_html .= '
'.$this->l('Description').''. $this->l('SoColissimo is a service offered by La Poste, which allows you to offer buyers 5 modes of delivery.').' :

'.$this->l('This module is free and allows you to activate the offer on your store.').'

>'.$this->l('Documentation').'<

 
'.$this->l('Settings').'

'.$this->l('To open your SoColissimo account, please contact "La Poste" at this phone number: 3634 (French phone number).').'

' . $this->l('Id user for back office SoColissimo.') . '

'.$this->l('Secure key for back office SoColissimo.').'

'.$this->l('Day(s)').'

' . $this->l('Average time of preparation of materials.') . '
' .$this->l('Average time must be the same in Coliposte back office.').'

€ HT

'. $this->l('Additional cost if making appointments.') . '
' .$this->l('Additional cost must be the same in Coliposte back office.').'

--------------------------------------------------------------------------------------------------------

' .$this->l('Be VERY CAREFUL with these settings, change may cause a malfunction of the module.'). '

' . $this->l('Url of back office SoColissimo.') . '

'.$this->l('Enable or disable the \'check availability\' of SoColissimo service.').'

' . $this->l('The URL of supervision is to ensure the availability of the service socolissimo. It is not advisable to disabled.') . '

 
'.$this->l('Information').'

'.$this->l('Please fill in these two addresses in your Back Office SoColissimo.').' :


'.htmlentities($this->url,ENT_NOQUOTES, 'UTF-8').'

'.htmlentities($this->url,ENT_NOQUOTES, 'UTF-8').'

'; } private function _postValidation() { if (Tools::getValue('id_user') == NULL) $this->_postErrors[] = $this->l('ID SO not specified'); if (Tools::getValue('key') == NULL) $this->_postErrors[] = $this->l('Key SO not specified'); if (Tools::getValue('dypreparationtime') == NULL) $this->_postErrors[] = $this->l('Preparation time not specified'); elseif (!Validate::isInt(Tools::getValue('dypreparationtime'))) $this->_postErrors[] = $this->l('Invalid preparation time'); if (Tools::getValue('overcost') == NULL) $this->_postErrors[] = $this->l('Overcost not specified'); elseif (!Validate::isFloat(Tools::getValue('overcost'))) $this->_postErrors[] = $this->l('Invalid overcost'); } private function _postProcess() { if (Configuration::updateValue('SOCOLISSIMO_ID', Tools::getValue('id_user')) AND Configuration::updateValue('SOCOLISSIMO_KEY', Tools::getValue('key')) AND Configuration::updateValue('SOCOLISSIMO_URL', pSQL(Tools::getValue('url_so'))) AND Configuration::updateValue('SOCOLISSIMO_PREPARATION_TIME', (int)(Tools::getValue('dypreparationtime'))) AND Configuration::updateValue('SOCOLISSIMO_OVERCOST', (float)(Tools::getValue('overcost'))) AND Configuration::updateValue('SOCOLISSIMO_SUP_URL', Tools::getValue('url_sup')) AND Configuration::updateValue('SOCOLISSIMO_OVERCOST_TAX', Tools::getValue('id_tax_rules_group')) AND Configuration::updateValue('SOCOLISSIMO_SUP', (int)(Tools::getValue('sup_active')))) { //save old carrier id if change if (!in_array((int)(Tools::getValue('carrier')), explode('|',Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST')))) Configuration::updateValue('SOCOLISSIMO_CARRIER_ID_HIST', Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST').'|'.(int)(Tools::getValue('carrier'))); $dataSync = (($so_login = Configuration::get('SOCOLISSIMO_ID')) ? '' : ''); $this->_html .= $this->displayConfirmation($this->l('Configuration updated').$dataSync); } else $this->_html .= '
nok '.$this->l('Cannot save settings').'
'; } public function hookExtraCarrier($params) { global $smarty, $cookie; $customer = new Customer($params['address']->id_customer); $gender = array('1'=>'MR','2'=>'MME'); if (in_array((int)($customer->id_gender),array(1,2))) $cecivility = $gender[(int)($customer->id_gender)]; else $cecivility = 'MR'; $carrierSo = new Carrier((int)(Configuration::get('SOCOLISSIMO_CARRIER_ID'))); if (isset($carrierSo) AND $carrierSo->active) { $signature = $this->make_key(substr($this->lower($params['address']->lastname),0,34), (int)(Configuration::Get('SOCOLISSIMO_PREPARATION_TIME')), number_format((float)($params['cart']->getOrderShippingCost($carrierSo->id, true)), 2, ',', ''), (int)($params['address']->id_customer),(int)($params['address']->id)); $orderId = $this->formatOrderId((int)($params['address']->id)); $inputs = array('PUDOFOID' => Configuration::get('SOCOLISSIMO_ID'), 'ORDERID' => $orderId, 'CENAME' => substr($this->lower($params['address']->lastname),0, 34), 'TRCLIENTNUMBER' => $this->upper((int)($params['address']->id_customer)), 'CECIVILITY' => $cecivility, 'CEFIRSTNAME' => substr($this->lower($params['address']->firstname),0,29), 'CECOMPANYNAME' => substr($this->upper($params['address']->company),0,38), 'CEEMAIL' => $params['cookie']->email, 'CEPHONENUMBER' => str_replace(array(' ', '.', '-', ',', ';', '+', '/', '\\', '+', '(', ')'),'',$params['address']->phone_mobile), 'CEADRESS3' => substr($this->upper($params['address']->address1),0,38), 'CEADRESS4' => substr($this->upper($params['address']->address2),0,38), 'CEZIPCODE' => $params['address']->postcode, 'CETOWN' => substr($this->upper($params['address']->city),0,32), 'DYWEIGHT' => ((float)($params['cart']->getTotalWeight()) * 1000), 'SIGNATURE' => htmlentities($signature,ENT_NOQUOTES, 'UTF-8'), 'TRPARAMPLUS' => (int)($carrierSo->id), 'DYFORWARDINGCHARGES' => number_format((float)($params['cart']->getOrderShippingCost($carrierSo->id)), 2, ',', ''), 'DYPREPARATIONTIME' => (int)(Configuration::Get('SOCOLISSIMO_PREPARATION_TIME')), 'TRRETURNURLKO' => htmlentities($this->url,ENT_NOQUOTES, 'UTF-8'), 'TRRETURNURLOK' => htmlentities($this->url,ENT_NOQUOTES, 'UTF-8')); $serialsInput = ''; foreach($inputs as $key => $val) $serialsInput .= '&'.$key.'='.$val; $serialsInput = ltrim($serialsInput, '&'); $row['id_carrier'] = (int)($carrierSo->id); $smarty->assign(array('urlSo' => Configuration::get('SOCOLISSIMO_URL').'?trReturnUrlKo='.htmlentities($this->url,ENT_NOQUOTES, 'UTF-8'),'id_carrier' => (int)($row['id_carrier']), 'inputs' => $inputs, 'serialsInput' => $serialsInput, 'finishProcess' => $this->l('To choose SoColissimo, click on a delivery method'))); $country = new Country((int)($params['address']->id_country)); $carriers = Carrier::getCarriers($cookie->id_lang, true , false,false, NULL, ALL_CARRIERS); $ids = array(); foreach($carriers as $carrier) $ids[] = $carrier['id_carrier']; if ($this->getDeliveryInfos((int)$cookie->id_cart, (int)$cookie->id_customer)) $smarty->assign('already_select_delivery', true); else $smarty->assign('already_select_delivery', false); if (($country->iso_code == 'FR') AND (Configuration::Get('SOCOLISSIMO_ID') != NULL) AND (Configuration::get('SOCOLISSIMO_KEY') != NULL) AND $this->checkAvailibility() AND $this->checkSoCarrierAvailable((int)(Configuration::get('SOCOLISSIMO_CARRIER_ID'))) AND in_array((int)(Configuration::get('SOCOLISSIMO_CARRIER_ID')),$ids)) { return $this->display(__FILE__, 'socolissimo_carrier.tpl'); } else { $smarty->assign('ids', explode('|',Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST'))); return $this->display(__FILE__, 'socolissimo_error.tpl'); } } } public function hooknewOrder($params) { global $cookie; if ($params['order']->id_carrier != Configuration::get('SOCOLISSIMO_CARRIER_ID')) return; $order = $params['order']; $order->id_address_delivery = $this->isSameAddress((int)($order->id_address_delivery), (int)($order->id_cart), (int)($order->id_customer)); $order->update(); } public function hookAdminOrder($params) { $deliveryMode = array('DOM' => 'Livraison à domicile', 'BPR' => 'Livraison en Bureau de Poste', 'A2P' => 'Livraison Commerce de proximité', 'MRL' => 'Livraison Commerce de proximité', 'CIT' => 'Livraison en Cityssimo', 'ACP' => 'Agence ColiPoste', 'CDI' => 'Centre de distribution', 'RDV' => 'Livraison sur Rendez-vous'); $order = new Order($params['id_order']); $addressDelivery = new Address((int)($order->id_address_delivery), (int)($params['cookie']->id_lang)); $soCarrier = new Carrier((int)(Configuration::get('SOCOLISSIMO_CARRIER_ID'))); $deliveryInfos = $this->getDeliveryInfos((int)($order->id_cart),(int)($order->id_customer)); if (((int)($order->id_carrier) == (int)($soCarrier->id) OR in_array((int)($order->id_carrier), explode('|',Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST')))) AND !empty($deliveryInfos)) { $html = '

'.$this->l('So Colissimo').''; $html .= ''.$this->l('Delivery mode').' : '; switch ($deliveryInfos['delivery_mode']) { case 'DOM': case 'RDV': $html .= $deliveryMode[$deliveryInfos['delivery_mode']].'

'; $html .=''.$this->l('Customer').' : '.Tools::htmlentitiesUTF8($addressDelivery->firstname).' '.Tools::htmlentitiesUTF8($addressDelivery->lastname).'
'. (!empty($deliveryInfos['cecompanyname']) ? ''.$this->l('Company').' : '.Tools::htmlentitiesUTF8($deliveryInfos['cecompanyname']).'
' : '' ). (!empty($deliveryInfos['ceemail']) ? ''.$this->l('E-mail address').' : '.Tools::htmlentitiesUTF8($deliveryInfos['ceemail']).'
' : '' ). (!empty($deliveryInfos['cephonenumber']) ? ''.$this->l('Phone').' : '.Tools::htmlentitiesUTF8($deliveryInfos['cephonenumber']).'

' : '' ). ''.$this->l('Customer address').' :
' .(Tools::htmlentitiesUTF8($addressDelivery->address1) ? Tools::htmlentitiesUTF8($addressDelivery->address1).'
' : '') .(!empty($addressDelivery->address2) ? Tools::htmlentitiesUTF8($addressDelivery->address2).'
' : '') .(!empty($addressDelivery->postcode) ? Tools::htmlentitiesUTF8($addressDelivery->postcode).'
' : '') .(!empty($addressDelivery->city) ? Tools::htmlentitiesUTF8($addressDelivery->city).'
' : '') .(!empty($addressDelivery->country) ? Tools::htmlentitiesUTF8($addressDelivery->country).'
' : '') .(!empty($addressDelivery->other) ? '
'.$this->l('Other').' : '.Tools::htmlentitiesUTF8($addressDelivery->other).'

' : '') .(!empty($deliveryInfos['cedoorcode1']) ? ''.$this->l('Door code').' 1 : '.Tools::htmlentitiesUTF8($deliveryInfos['cedoorcode1']).'
' : '' ) .(!empty($deliveryInfos['cedoorcode2']) ? ''.$this->l('Door code').' 2 : '.Tools::htmlentitiesUTF8($deliveryInfos['cedoorcode2']).'
' : '' ) .(!empty($deliveryInfos['cedeliveryinformation']) ? ''.$this->l('Delivery information').' : '.Tools::htmlentitiesUTF8($deliveryInfos['cedeliveryinformation']).'

' : '' ); break; default: $html .= str_replace('+',' ',$deliveryMode[$deliveryInfos['delivery_mode']]).'
' .(!empty($deliveryInfos['prid']) ? ''.$this->l('Pick up point ID').' : '.Tools::htmlentitiesUTF8($deliveryInfos['prid']).'
' : '' ) .(!empty($deliveryInfos['prname']) ? ''.$this->l('Pick up point').' : '.Tools::htmlentitiesUTF8($deliveryInfos['prname']).'
' : '' ) .''.$this->l('Pick up point address').' :
' .(!empty($deliveryInfos['pradress1']) ? Tools::htmlentitiesUTF8($deliveryInfos['pradress1']).'
' : '' ) .(!empty($deliveryInfos['pradress2']) ? Tools::htmlentitiesUTF8($deliveryInfos['pradress2']).'
' : '' ) .(!empty($deliveryInfos['pradress3']) ? Tools::htmlentitiesUTF8($deliveryInfos['pradress3']).'
' : '' ) .(!empty($deliveryInfos['pradress4']) ? Tools::htmlentitiesUTF8($deliveryInfos['pradress4']).'
' : '' ) .(!empty($deliveryInfos['przipcode']) ? Tools::htmlentitiesUTF8($deliveryInfos['przipcode']).'
' : '' ) .(!empty($deliveryInfos['prtown']) ? Tools::htmlentitiesUTF8($deliveryInfos['prtown']).'
' : '' ) .(!empty($deliveryInfos['ceemail']) ? ''.$this->l('Email').' : '.Tools::htmlentitiesUTF8($deliveryInfos['ceemail']).'
' : '' ) .(!empty($deliveryInfos['cephonenumber']) ? ''.$this->l('Phone').' : '.Tools::htmlentitiesUTF8($deliveryInfos['cephonenumber']).'

' : '' ); break; } $html .= '
'; return $html; } } public function hookupdateCarrier($params) { if ((int)($params['id_carrier']) == (int)(Configuration::get('SOCOLISSIMO_CARRIER_ID'))) { Configuration::updateValue('SOCOLISSIMO_CARRIER_ID', (int)($params['carrier']->id)); Configuration::updateValue('SOCOLISSIMO_CARRIER_ID_HIST', Configuration::get('SOCOLISSIMO_CARRIER_ID_HIST').'|'.(int)($params['carrier']->id)); } } public function make_key($ceName, $dyPraparationTime, $dyForwardingCharges, $trClientNumber, $orderId) { return sha1(Configuration::get('SOCOLISSIMO_ID').$ceName.$dyPraparationTime.$dyForwardingCharges.$trClientNumber.self::formatOrderId($orderId).Configuration::get('SOCOLISSIMO_KEY')); } public static function createSoColissimoCarrier($config) { $carrier = new Carrier(); $carrier->name = $config['name']; $carrier->id_tax_rules_group = $config['id_tax_rules_group']; $carrier->id_zone = $config['id_zone']; $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 ($language['iso_code'] == 'fr') $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']]; if ($language['iso_code'] == 'en') $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']]; } if ($carrier->add()) { Configuration::updateValue('SOCOLISSIMO_CARRIER_ID',(int)($carrier->id)); $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']).'\')'); } $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) { Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'carrier_zone VALUE (\''.(int)($carrier->id).'\',\''.(int)($zone['id_zone']).'\')'); Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'delivery VALUE (\'\',\''.(int)($carrier->id).'\',\''.(int)($rangePrice->id).'\',NULL,\''.(int)($zone['id_zone']).'\',\'1\')'); Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'delivery VALUE (\'\',\''.(int)($carrier->id).'\',NULL,\''.(int)($rangeWeight->id).'\',\''.(int)($zone['id_zone']).'\',\'1\')'); } //copy logo if (!copy(dirname(__FILE__).'/socolissimo.jpg',_PS_SHIP_IMG_DIR_.'/'.$carrier->id.'.jpg')) return false; return true; } else return false; } public function getDeliveryInfos($idCart,$idCustomer) { $result = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'socolissimo_delivery_info WHERE id_cart = '.(int)($idCart).' AND id_customer = '.(int)($idCustomer)); return $result; } public function isSameAddress($idAddress,$idCart,$idCustomer) { $return = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'socolissimo_delivery_info WHERE id_cart =\''.(int)($idCart).'\' AND id_customer =\''.(int)($idCustomer).'\''); $psAddress = new Address((int)($idAddress)); $newAddress = new Address(); if ($this->upper($psAddress->lastname) != $this->upper($return['prname']) || $this->upper($psAddress->firstname) != $this->upper($return['prfirstname']) || $this->upper($psAddress->address1) != $this->upper($return['pradress3']) || $this->upper($psAddress->address2) != $this->upper($return['pradress2']) || $this->upper($psAddress->postcode) != $this->upper($return['przipcode']) || $this->upper($psAddress->city) != $this->upper($return['prtown']) || str_replace(array(' ', '.', '-', ',', ';', '+', '/', '\\', '+', '(', ')'),'',$psAddress->phone_mobile) != $return['cephonenumber']) { $newAddress->id_customer = (int)($idCustomer); $newAddress->lastname = substr($return['prname'],0,32); $newAddress->firstname = substr($return['prfirstname'],0,32); $newAddress->postcode = $return['przipcode']; $newAddress->city = $return['prtown']; $newAddress->id_country = Country::getIdByName(null, 'france'); $newAddress->alias = 'So Colissimo - '.date('d-m-Y'); if (!in_array($return['delivery_mode'], array('DOM','RDV'))) { $newAddress->active = 1; $newAddress->deleted = 1; $newAddress->address1 = $return['pradress1']; $newAddress->add(); } else { $newAddress->address1 = $return['pradress3']; ((isset($return['pradress2'])) ? $newAddress->address2 = $return['pradress2'] : $newAddress->address2 = ''); ((isset($return['pradress1'])) ? $newAddress->other .= $return['pradress1'] : $newAddress->other = ''); ((isset($return['pradress4'])) ? $newAddress->other .= ' | '.$return['pradress4'] : $newAddress->other = ''); $newAddress->postcode = $return['przipcode']; $newAddress->city = $return['prtown']; $newAddress->id_country = Country::getIdByName(null, 'france'); $newAddress->alias = 'So Colissimo - '.date('d-m-Y'); $newAddress->add(); } return (int)($newAddress->id); } else return (int)($psAddress->id); } public function checkZone($id_carrier) { $result = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'carrier_zone WHERE id_carrier = '.(int)($id_carrier)); if ($result) return true; else return false; } public function checkGroup($id_carrier) { $result = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'carrier_group WHERE id_carrier = '.(int)($id_carrier)); if ($result) return true; else return false; } public function checkRange($id_carrier) { switch (Configuration::get('PS_SHIPPING_METHOD')) { case '0' : $sql = 'SELECT * FROM '._DB_PREFIX_.'range_price WHERE id_carrier = '.(int)($id_carrier); break; case '1' : $sql = 'SELECT * FROM '._DB_PREFIX_.'range_weight WHERE id_carrier = '.(int)($id_carrier); break; } $result = Db::getInstance()->getRow($sql); if ($result) return true; else return false; } public function checkDelivery($id_carrier) { $result = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'delivery WHERE id_carrier = '.(int)($id_carrier)); if ($result) return true; else return false; } public function upper($strIn) { $strOut = Tools::link_rewrite($strIn); return strtoupper(str_replace('-',' ',$strOut)); } public function lower($strIn) { $strOut = Tools::link_rewrite($strIn); return strtolower(str_replace('-',' ',$strOut)); } public function formatOrderId($id) { if (strlen($id)<5) while (strLen($id) != 5) { $id = '0'.$id; } return $id; } public function checkAvailibility() { if (Configuration::get('SOCOLISSIMO_SUP')) { $ctx = stream_context_create(array('http' => array('timeout' => 1))); $return = @file_get_contents(Configuration::get('SOCOLISSIMO_SUP_URL'), 0, $ctx); if (ini_get('allow_url_fopen') == 0) return true; else { if (!empty($return)) { preg_match('[OK]',$return, $matches); if ($matches[0]=='OK') return true; else return false; } } } else return true; } public function displaySoError($key) { return $this->errorMessage[$key]; } private function checkSoCarrierAvailable($id_carrier) { global $cart, $defaultCountry; $carrier = new Carrier((int)($id_carrier)); $address = new Address((int)($cart->id_address_delivery)); $id_zone = Address::getZoneById((int)($address->id)); // Get only carriers that are compliant with shipping method if ((Configuration::get('PS_SHIPPING_METHOD') AND $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) OR (!Configuration::get('PS_SHIPPING_METHOD') AND $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) { return false; } // If out-of-range behavior carrier is set on "Desactivate carrier" if ($carrier->range_behavior) { // Get id zone if (isset($cart->id_address_delivery) AND $cart->id_address_delivery) $id_zone = Address::getZoneById((int)($cart->id_address_delivery)); else $id_zone = (int)$defaultCountry->id_zone; // Get only carriers that have a range compatible with cart if ((Configuration::get('PS_SHIPPING_METHOD') AND (!Carrier::checkDeliveryPriceByWeight((int)($carrier->id), $cart->getTotalWeight(), $id_zone))) OR (!Configuration::get('PS_SHIPPING_METHOD') AND (!Carrier::checkDeliveryPriceByPrice((int)($carrier->id), $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)))) { return false; } } return true; } public function getOrderShippingCost($params,$shipping_cost) { global $cart; $deliveryInfo = $this->getDeliveryInfos($cart->id, $cart->id_customer); if (!empty($deliveryInfo)) if ($deliveryInfo['delivery_mode'] == 'RDV') $shipping_cost += (float)(Configuration::get('SOCOLISSIMO_OVERCOST')); return $shipping_cost; } public function getOrderShippingCostExternal($params){} }