name = 'lapostews'; $this->tab = 'shipping_logistics'; $this->version = '1.0-2'; $this->author = 'Antadis'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('La Poste webservices'); $this->description = $this->l('Allows to manage parcels with La Poste via webservices'); } function install() { # Add admin tabs $tabs_i18n = array( 'fr' => 'Gestion des envois', 'en' => 'Parcel management', ); $t = new Tab(); $t->id_parent = (int) Tab::getIdFromClassName('AdminOrders'); $st->position = (int) Tab::getNewLastPosition($st->id_parent); $t->active = TRUE; $t->module = 'lapostews'; $t->class_name = 'AdminLaPosteWS'; foreach(Language::getLanguages() as $lang) { if(isset($tabs_i18n[$lang['iso_code']])) { $t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']]; } else { $t->name[$lang['id_lang']] = $tabs_i18n['en']; } } $t->save();# Add admin tabs $tabs_i18n = array( 'fr' => 'Bordereaux', 'en' => 'Summaries', ); $t = new Tab(); $t->id_parent = (int) Tab::getIdFromClassName('AdminOrders'); $st->position = (int) Tab::getNewLastPosition($st->id_parent); $t->active = TRUE; $t->module = 'lapostews'; $t->class_name = 'AdminLaPosteSummary'; foreach(Language::getLanguages() as $lang) { if(isset($tabs_i18n[$lang['iso_code']])) { $t->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']]; } else { $t->name[$lang['id_lang']] = $tabs_i18n['en']; } } $t->save(); return Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'lapostews2` ( `id_order` INTEGER UNSIGNED NOT NULL, `id_employee` INTEGER UNSIGNED NOT NULL, `shipping_number` VARCHAR(64) NOT NULL, `date_add` DATETIME NOT NULL, PRIMARY KEY(`id_order`, `date_add`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ') && Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'lapostews_pr` ( `id_pr` VARCHAR(6) NOT NULL, `name` VARCHAR(255) NOT NULL, `address1` VARCHAR(255) NOT NULL, `address2` VARCHAR(255) NOT NULL, `address3` VARCHAR(255) NOT NULL, `address4` VARCHAR(255) NOT NULL, `postcode` VARCHAR(6) NOT NULL, `city` VARCHAR(255) NOT NULL, `xcoords` VARCHAR(24) NOT NULL, `ycoords` VARCHAR(24) NOT NULL, `type` VARCHAR(6) NOT NULL, `code1` VARCHAR(8) NOT NULL, `code2` VARCHAR(8) NOT NULL, PRIMARY KEY(`id_pr`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ') && parent::install(); } public function uninstall() { return Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'lapostews2`') && Db::getInstance()->ExecuteS('DROP TABLE IF EXISTS `'._DB_PREFIX_.'lapostews_pr`') && parent::uninstall(); } public function getContent() { global $cookie; if(Tools::isSubmit('submitUpdate')) { Configuration::updateValue('LAPOSTEWS_CARRIERS', serialize(Tools::getValue('carriers', array()))); Configuration::updateValue('LAPOSTEWS_CONTRACT', Tools::getValue('contract')); Configuration::updateValue('LAPOSTEWS_API_PASSWORD', Tools::getValue('apipassword')); Configuration::updateValue('LAPOSTEWS_API_CONTRACT', Tools::getValue('apicontract')); Configuration::updateValue('LAPOSTEWS_MODE', Tools::getValue('mode')); Configuration::updateValue('LAPOSTEWS_COMMERCIALNAME', Tools::getValue('commercialname')); Configuration::updateValue('LAPOSTEWS_SHIPPING_SITE', Tools::getValue('shippingsite')); Configuration::updateValue('LAPOSTEWS_SHIPPING_SITE_CODE', Tools::getValue('shippingsite_code')); Configuration::updateValue('LAPOSTEWS_SUMMARIES_COUNT', Tools::getValue('summaries_count')); Configuration::updateValue('LAPOSTEWS_EXP_ADDR1', Tools::getValue('exp_addr1')); Configuration::updateValue('LAPOSTEWS_EXP_ADDR2', Tools::getValue('exp_addr2')); Configuration::updateValue('LAPOSTEWS_EXP_CITY', Tools::getValue('exp_city')); Configuration::updateValue('LAPOSTEWS_EXP_COMPANY', Tools::getValue('exp_company')); Configuration::updateValue('LAPOSTEWS_EXP_COUNTRY', Tools::getValue('exp_country')); Configuration::updateValue('LAPOSTEWS_EXP_EMAIL', Tools::getValue('exp_email')); Configuration::updateValue('LAPOSTEWS_EXP_FIRSTNAME', Tools::getValue('exp_firstname')); Configuration::updateValue('LAPOSTEWS_EXP_LASTNAME', Tools::getValue('exp_lastname')); Configuration::updateValue('LAPOSTEWS_EXP_PHONE', Tools::getValue('exp_phone')); Configuration::updateValue('LAPOSTEWS_EXP_POSTALCODE', Tools::getValue('exp_postalcode')); foreach(Tools::getValue('employee', array()) as $id_employee => $queue) { Configuration::updateValue('LAPOSTEWS_EMPL_'.(int) $id_employee, $queue); } $this->_html = '

'.$this->l('Configuration updated successfully').'


'; } $carriers = unserialize(Configuration::get('LAPOSTEWS_CARRIERS', serialize(array()))); $this->_html .= '
'.$this->l('Account settings').'


'.$this->l('API settings').'

'.$this->l('Mode:').'


'.$this->l('Parcel sender details').'


'.$this->l('Carrier selection').'

'; foreach(Db::getInstance()->ExecuteS(' SELECT c.* FROM `'._DB_PREFIX_.'carrier` c ') as $carrier) { $this->_html .= '
'; } $this->_html .= '


'.$this->l('Queues configuration').' '; foreach(Employee::getEmployees() as $employee) { $this->_html .= '

'; } $this->_html .= '



'; return $this->_html; } public function hookUpdateCarrier($params) { $new_carrier_id = (int) Db::getInstance()->getValue('SELECT MAX(`id_carrier`) FROM `'._DB_PREFIX_.'carrier`'); $carriers = Configuration::get('LAPOSTEWS_CARRIERS'); if(in_array((int) $params['id_carrier'], $carriers)) { $carriers[] = (int) $new_carrier_id; Configuration::updateValue('LAPOSTEWS_CARRIERS', serialize($carriers)); } } }