name = 'expeditor'; if (preg_match("/1\.4/", _PS_VERSION_)) $this->tab = 'administration'; else $this->tab = 'Import/export'; $this->version = '2.3.12'; $this->author = 'PrestaShop'; $this->module_key = 'f4caec1f4133b3333c081cd6a4cadfca'; parent::__construct(); /** Backward compatibility */ require(_PS_MODULE_DIR_.'/expeditor/backward_compatibility/backward.php'); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Expeditor Inet'); $this->description = $this->l('Manage yours orders between Prestashop and your Expeditor Inet software'); } public function install() { global $cookie; if (!parent::install()) return false; $this->installDB(); if (!$id_tab = $this->installAdmin()) return false; if (!Configuration::get('EXPEDITOR_STATE_EXP')) Configuration::updateValue('EXPEDITOR_STATE_EXP', _PS_OS_PREPARATION_); if (!Configuration::get('EXPEDITOR_STATE_IMP')) Configuration::updateValue('EXPEDITOR_STATE_IMP', _PS_OS_PREPARATION_); if (!Configuration::get('EXPEDITOR_CARRIER')) Configuration::updateValue('EXPEDITOR_CARRIER', 0); if (!Configuration::get('EXPEDITOR_MULTIPLY')) Configuration::updateValue('EXPEDITOR_MULTIPLY', 1000); if (!Configuration::get('EXPEDITOR_CARRIER_CODES')) Configuration::updateValue('EXPEDITOR_CARRIER_CODES', NULL); if (!sizeof($this->_errors)) Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.intval(Tab::getIdFromClassName('AdminModules')).intval($cookie->id_employee))); foreach ($this->_errors as $errors) echo $errors.'
'; unset($errors); return false; } function installDB() { Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'expeditor` ( `id_expeditor` INT NOT NULL AUTO_INCREMENT, `id_order` INT NOT NULL, `weight` FLOAT NOT NULL DEFAULT 0, `standard_size` BOOLEAN NOT NULL DEFAULT 1, `is_send` BOOLEAN NOT NULL DEFAULT 0, `date_add` DATETIME NOT NULL, `date_upd` DATETIME NOT NULL, PRIMARY KEY (`id_expeditor`), INDEX index_order_expeditor (`id_order`) );'); } function installAdmin() { $tab = new Tab(); $tab->class_name = 'AdminExpeditor'; if (version_compare(_PS_VERSION_, '1.5.0.0') >= 0) { $tab->id_parent = 10; Autoload::getInstance()->generateIndex(); } else $tab->id_parent = 3; $tab->module = $this->name; $tab->name[Configuration::get('PS_LANG_DEFAULT')] = $this->l('Expeditor Inet'); if ($tab->add()) return $tab->id; return false; } function uninstall() { Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'tab` WHERE `class_name` = \'AdminExpeditor\''); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'tab_lang` WHERE `id_tab` NOT IN (SELECT `id_tab` FROM `'._DB_PREFIX_.'tab`)'); return (parent::uninstall(false)); } public function getContent() { if (version_compare(_PS_VERSION_, '1.5.0.0') >= 0) { Autoload::getInstance()->generateIndex(); } $this->_html .= '

' . $this->l('Expeditor Inet') . ' ©

'; $this->_displayDownloadFile(); if (!empty($_POST) AND isset($_POST['id_order_state_exp']) AND isset($_POST['id_order_state_imp'])) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else { foreach ($this->_postErrors AS $err) { $this->_html .= '
'.$err.'
'; } unset($err); } } $this->_displayForm(); global $cookie; $this->_html .= '

'.$this->l('Direct access to Expeditor tab.').'

'; return $this->_html; } private function _displayForm() { global $cookie; $this->orderStateExp = Configuration::get('EXPEDITOR_STATE_EXP'); $this->orderStateImp = Configuration::get('EXPEDITOR_STATE_IMP'); $this->_html .= '
'; $this->_html .= '
'.$this->l('Settings').''; $this->_html .= ''; $this->_html .= '
'; $this->_html .= ''; $this->_html .= "

" . $this->l('Choose the order state which orders can be export to Expeditor.') . "

"; $this->_html .= '
'; $this->_html .= ''; $this->_html .= '
'; $this->_html .= ''; $this->_html .= "

" . $this->l('Choose the order state when orders are import into Prestashop.') . "

"; $this->_html .= '
'; //Carrier choice $this->_html .= $this->_displayCarrierSelects(); $this->_html .= ''; $this->_html .= '
'; $this->_html .= ''; $this->carrier = Configuration::get('EXPEDITOR_CARRIER'); $carriers = Carrier::getCarriers($cookie->id_lang, false, false, false, NULL, 5); foreach ($carriers as $carrier) { $this->_html .= ''; //list of Carriers codes $expeditor = new ExpeditorModule(); $product_codes = $expeditor->product_codes; $this->_html .= ''; } unset($carriers, $carrier); $this->_html .= '
'.$this->l('Carrier').' '.$this->l('Carrier_code').'
_html .= ' checked="true" '; $this->_html .= '>'.$carrier['name'].'
'; $this->_html .= "

" . $this->l('Choose the carrier "LaPoste", "ColiPoste" or like this.') . "

"; $this->_html .= '
'; $this->_html .= '
' . $this->l('Liste Orders') . '
 
PrestaShop Addons '.$this->l('This module has been developped by PrestaShop SA and can only be sold through').' addons.prestashop.com.
'.$this->l('Please report all bugs to').' addons@prestashop.com '.$this->l('or using our').' '.$this->l('contact form').'.
'; } private function _displayCarrierSelects() { $class = new ExpeditorModule(); } private function _postValidation() { if (!isset($_POST['id_order_state_imp']) OR empty($_POST['id_order_state_imp']) OR !is_numeric($_POST['id_order_state_imp']) ) $this->_postErrors[] = $this->l('No order state import specified'); if (!isset($_POST['id_order_state_exp']) OR empty($_POST['id_order_state_exp']) OR !is_numeric($_POST['id_order_state_exp']) ) $this->_postErrors[] = $this->l('No order state export specified'); if (!isset($_POST['EXPEDITOR_MULTIPLY']) OR empty($_POST['EXPEDITOR_MULTIPLY']) OR !is_numeric($_POST['EXPEDITOR_MULTIPLY']) ) $this->_postErrors[] = $this->l('Multiplier required (0 is allowed)'); } private function _postProcess() { global $cookie; Configuration::updateValue('EXPEDITOR_MULTIPLY', $_POST['EXPEDITOR_MULTIPLY']); $ids_carrier_conf = array(); if (isset($_POST['carrierbox'])) { foreach (Tools::getValue('carrierbox') as $id) $ids_carrier_conf[] = $id; Configuration::updateValue('EXPEDITOR_CARRIER', implode(',', $ids_carrier_conf)); } else $this->_html .= '
'.$this->l('Invalid carrier').'
'; $carriers = Carrier::getCarriers($cookie->id_lang, false, false, false, NULL, 5); foreach ($carriers as $carrier) { if (isset($_POST['product_codes_'.$carrier['id_carrier']])) { Configuration::updateValue('EXPEDITOR_CARRIER_CODES_'.$carrier['id_carrier'], $_POST['product_codes_'.$carrier['id_carrier']]); } else $this->_html .= '
'.$this->l('Invalid carrier code').'
'; } unset($carriers,$carrier); Configuration::updateValue('EXPEDITOR_STATE_EXP', Tools::getValue('id_order_state_exp')); Configuration::updateValue('EXPEDITOR_STATE_IMP', Tools::getValue('id_order_state_imp')); $this->_html .= '
ok '.$this->l('Settings updated').'
'; } private function _displayDownloadFile() { $this->_html .= '

'; $this->_html .= 'download ' . $this->l('Download Expeditor installation guide') . '
'; $this->_html .= 'download ' . $this->l('Download format file for import data') . ''; $this->_html .= '

'; } }