302 lines
10 KiB
PHP
302 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* 2007-2017 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
*
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
* @copyright 2007-2015 PrestaShop SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
include_once('classes/Expeditor.class.php');
|
|
|
|
class Expeditor extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'expeditor';
|
|
$this->tab = 'export';
|
|
$this->version = '3.0.9';
|
|
$this->author = 'PrestaShop';
|
|
$this->need_instance = 0;
|
|
|
|
$this->module_key = 'f4caec1f4133b3333c081cd6a4cadfca';
|
|
$this->author_address = '0x64aa3c1e4034d07015f639b0e171b0d7b27d01aa';
|
|
|
|
$this->bootstrap = true;
|
|
$this->controller_name = 'AdminExpeditor';
|
|
$this->controller_name_ajax = 'AdminAjaxExpeditor';
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Expeditor Inet');
|
|
$this->description = $this->l('Manage yours orders between Prestashop and your Expeditor Inet software');
|
|
|
|
$this->js_path = $this->_path.'views/js/';
|
|
$this->css_path = $this->_path.'views/css/';
|
|
$this->img_path = $this->_path.'views/img/';
|
|
$this->logo_path = $this->_path.'logo.png';
|
|
$this->module_path = $this->_path;
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
|
|
|
|
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
|
}
|
|
|
|
/**
|
|
* Don't forget to create update methods if needed:
|
|
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
|
|
*/
|
|
public function install()
|
|
{
|
|
Configuration::updateValue('EXPEDITOR_STATE_EXP', null);
|
|
Configuration::updateValue('EXPEDITOR_STATE_IMP', null);
|
|
Configuration::updateValue('EXPEDITOR_CARRIER', 0);
|
|
Configuration::updateValue('EXPEDITOR_MULTIPLY', 1000);
|
|
|
|
if (parent::install() && $this->installTab()) {
|
|
return (true);
|
|
} else {
|
|
$this->_errors[] = $this->l('There was an error during the installation.
|
|
Please contact us through Addons website');
|
|
return (false);
|
|
}
|
|
|
|
return parent::install();
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
Configuration::deleteByName('EXPEDITOR_STATE_EXP');
|
|
Configuration::deleteByName('EXPEDITOR_STATE_IMP');
|
|
Configuration::deleteByName('EXPEDITOR_CARRIER');
|
|
Configuration::deleteByName('EXPEDITOR_MULTIPLY');
|
|
// Configuration::deleteByName('EXPEDITOR_CARRIER_CODES');
|
|
|
|
$this->uninstallTab();
|
|
|
|
return parent::uninstall();
|
|
}
|
|
|
|
public function installTab()
|
|
{
|
|
$tab = new Tab();
|
|
$tab->active = 1;
|
|
$tab->class_name = $this->controller_name;
|
|
$tab->name = array();
|
|
foreach (Language::getLanguages(true) as $lang) {
|
|
$tab->name[$lang['id_lang']] = 'Expeditor Inet';
|
|
}
|
|
$tab->id_parent = 10;
|
|
$tab->module = $this->name;
|
|
$result = $tab->add();
|
|
|
|
$tab = new Tab();
|
|
$tab->active = 1;
|
|
$tab->class_name = $this->controller_name_ajax;
|
|
$tab->name = array();
|
|
foreach (Language::getLanguages(true) as $lang) {
|
|
$tab->name[$lang['id_lang']] = $this->name;
|
|
}
|
|
unset($lang);
|
|
$tab->id_parent = -1;
|
|
$tab->module = $this->name;
|
|
$result = $tab->add();
|
|
|
|
return ($result);
|
|
}
|
|
|
|
public function uninstallTab()
|
|
{
|
|
$id_tab = (int)Tab::getIdFromClassName('AdminExpeditor');
|
|
if ($id_tab) {
|
|
$tab = new Tab($id_tab);
|
|
if (Validate::isLoadedObject($tab)) {
|
|
return ($tab->delete());
|
|
} else {
|
|
$return = false;
|
|
}
|
|
} else {
|
|
$return = true;
|
|
}
|
|
|
|
$id_tab = (int)Tab::getIdFromClassName('AdminAjaxExpeditor');
|
|
if ($id_tab) {
|
|
$tab = new Tab($id_tab);
|
|
if (Validate::isLoadedObject($tab)) {
|
|
return ($tab->delete());
|
|
} else {
|
|
$return = false;
|
|
}
|
|
} else {
|
|
$return = true;
|
|
}
|
|
|
|
return ($return);
|
|
}
|
|
|
|
public function loadAsset()
|
|
{
|
|
// Load CSS
|
|
$css = array(
|
|
$this->css_path.'font-awesome.min.css',
|
|
$this->css_path.'bootstrap-select.min.css',
|
|
$this->css_path.'bootstrap-multiselect.css',
|
|
$this->css_path.'faq.css',
|
|
$this->css_path.'sweetalert.css',
|
|
$this->css_path.$this->name.'.css',
|
|
);
|
|
|
|
$this->context->controller->addCSS($css, 'all');
|
|
|
|
// Load JS
|
|
$jss = array(
|
|
$this->js_path.'faq.js',
|
|
$this->js_path.'bootstrap-multiselect.js',
|
|
$this->js_path.'sweetalert.min.js',
|
|
$this->js_path.'bootstrap.min.js',
|
|
$this->js_path.'bootstrap-filestyle.min.js',
|
|
$this->js_path.'papaparse.min.js',
|
|
$this->js_path.'treatCsvFile.js',
|
|
$this->js_path.$this->name.'.js'
|
|
);
|
|
|
|
$this->context->controller->addJS($jss);
|
|
// Clean memory
|
|
unset($jss, $css);
|
|
}
|
|
|
|
/**
|
|
* Load the configuration form
|
|
*/
|
|
public function getContent()
|
|
{
|
|
$id_lang = $this->context->language->id;
|
|
/**
|
|
* If values have been submitted in the form, process.
|
|
*/
|
|
// We load asset
|
|
$this->loadAsset();
|
|
if (((bool)Tools::isSubmit('submitExpeditorModule')) == true) {
|
|
$this->postProcess();
|
|
}
|
|
|
|
// API FAQ Update
|
|
include_once('classes/APIFAQClass.php');
|
|
$api = new APIFAQ();
|
|
$api_json = Tools::jsonDecode($api->getData($this));
|
|
$apifaq_json_categories = $api_json->categories;
|
|
|
|
//get List carriers
|
|
$carriers = Carrier::getCarriers($id_lang, false, false, false, null, 5);
|
|
|
|
$expeditor = new ExpeditorClass();
|
|
$product_codes = $expeditor->product_codes;
|
|
|
|
//get list of states
|
|
$order_states_exp = OrderState::getOrderStates($id_lang);
|
|
|
|
$admin_token = '&token=' . Tools::getAdminTokenLite($this->controller_name_ajax);
|
|
$controller_url = 'index.php?tab=' . $this->controller_name_ajax.$admin_token;
|
|
|
|
//get list state to export in database
|
|
$state_exp = Configuration::get('EXPEDITOR_STATE_EXP');
|
|
$state_exp = explode(',', $state_exp);
|
|
|
|
//get carriers list in database
|
|
$listcarriers = Configuration::get('EXPEDITOR_CARRIER');
|
|
$listcarriers = explode(',', $listcarriers);
|
|
|
|
//get carriers codes in database
|
|
$listcodes = array();
|
|
foreach ($carriers as $value) {
|
|
$tmp = Configuration::get('EXPEDITOR_CARRIER_CODES_'.$value['id_carrier']);
|
|
$listcodes[$value['id_carrier']][] = $tmp;
|
|
}
|
|
|
|
//get label weight unit
|
|
$weight = Configuration::get('EXPEDITOR_MULTIPLY');
|
|
if ($weight == 1000) {
|
|
$weight_label = 'gram';
|
|
} else {
|
|
$weight_label = 'kilogram';
|
|
}
|
|
|
|
//get list orders to display in the table
|
|
$listOrders = ExpeditorClass::getOrders();
|
|
|
|
$this->context->smarty->assign(array(
|
|
'module_name' => $this->name,
|
|
'module_version' => $this->version,
|
|
'module_enabled' => (int)$this->active,
|
|
'controller_url' => $controller_url,
|
|
'controller_name' => $this->controller_name_ajax,
|
|
'token' => Tools::getAdminTokenLite($this->controller_name_ajax),
|
|
'debug_mode' => (int)_PS_MODE_DEV_,
|
|
'module_docs' => __PS_BASE_URI__.'modules/expeditor/docs/',
|
|
'product_codes' => $product_codes,
|
|
'order_states_exp' => $order_states_exp,
|
|
'state_exp' => $state_exp,
|
|
'listcarriers' => $listcarriers,
|
|
'listcodes' => $listcodes,
|
|
'weight_unit' => Configuration::get('EXPEDITOR_MULTIPLY'),
|
|
'weight_unit_label' => $weight_label,
|
|
'state_imp' => Configuration::get('EXPEDITOR_STATE_IMP'),
|
|
'listOrders' => $listOrders,
|
|
'apifaq' => $apifaq_json_categories,
|
|
'carriers' => $carriers,
|
|
'module_display' => $this->displayName,
|
|
'module_path' => $this->module_path,
|
|
'logo_path' => $this->logo_path,
|
|
'img_path' => $this->img_path,
|
|
'multishop' => (int)Shop::isFeatureActive(),
|
|
'ps_version' => (bool)version_compare(_PS_VERSION_, '1.6', '>'),
|
|
'rewriting_allow' => (int)Configuration::get('PS_REWRITING_SETTINGS'),
|
|
));
|
|
|
|
// Media::addJsDef('token', Tools::getAdminTokenLite($this->controller_name_ajax));
|
|
|
|
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configuration.tpl');
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Get an array of fresh data for table.tpl
|
|
**/
|
|
public function getTableOrders($data)
|
|
{
|
|
//get label weight unit
|
|
$weight = Configuration::get('EXPEDITOR_MULTIPLY');
|
|
if ($weight == 1000) {
|
|
$weight_label = 'gram';
|
|
} else {
|
|
$weight_label = 'kilogram';
|
|
}
|
|
|
|
$this->context->smarty->assign('weight_unit_label', $weight_label);
|
|
$this->context->smarty->assign('listOrders', $data);
|
|
return $this->context->smarty->fetch($this->local_path . '/views/templates/front/results/table.tpl');
|
|
}
|
|
}
|