135 lines
4.5 KiB
PHP
135 lines
4.5 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class FluxCatalog extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'fluxcatalog';
|
|
$this->version = '1.0.0';
|
|
$this->author = 'Antadis';
|
|
$this->tab = 'advertising_marketing';
|
|
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
|
|
$this->need_instance = 0;
|
|
$this->bootstrap = true;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Flux catalogue XML');
|
|
$this->description = $this->l('Modifier les paramètres des urls.');
|
|
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module ? All your settings will be lost.');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (Shop::isFeatureActive()) {
|
|
Shop::setContext(Shop::CONTEXT_ALL);
|
|
}
|
|
|
|
return (parent::install()
|
|
&& Configuration::updateValue('FLUXCATALOG_TRACKING', '')
|
|
);
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
return (Configuration::deleteByName('FLUXCATALOG_TRACKING')
|
|
&& parent::uninstall()
|
|
);
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$output = '';
|
|
|
|
if (Tools::isSubmit('submitConfigure')) {
|
|
Configuration::updateValue('FLUXCATALOG_TRACKING', pSQL((string)Tools::getValue('FLUXCATALOG_TRACKING')));
|
|
$output .= $this->displayConfirmation($this->l('Paramètres enregistrés. Sera effectif lors du prochain export du catalogue.'));
|
|
}
|
|
|
|
|
|
$url_complete = _PS_BASE_URL_.Configuration::get('FLUXCATALOG_TRACKING');
|
|
|
|
$list_xml_files = array();
|
|
$files = glob(__DIR__.'/catalogs/'.'*.xml');
|
|
rsort($files);
|
|
|
|
$d = new DateTime('Tomorrow');
|
|
$next_export_filename = $d->format('Ymd').'_ventes.xml';
|
|
|
|
foreach ($files as $i => $absolute_file_path) {
|
|
if ($i==10) {
|
|
break;
|
|
}
|
|
$list_xml_files[] = basename($absolute_file_path);
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'url_complete' => $url_complete,
|
|
'next_export_filename' => $next_export_filename,
|
|
'list_xml_files' => $list_xml_files,
|
|
'path' => '/modules/'.$this->name.'/catalogs/'
|
|
));
|
|
|
|
$output .= $this->displayForm();
|
|
return $output.$this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
|
|
}
|
|
|
|
public function displayForm()
|
|
{
|
|
// Get default language
|
|
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$fields_form = array();
|
|
|
|
// paramètres supplémentaires url
|
|
$fields_form[]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('Paramètres Flux catalogue xml'),
|
|
),
|
|
'description' => $this->l('Ajouter un paramètre supplémentaire aux URLs dans les prochains flux xml.'),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('paramètres url'),
|
|
'desc' => $this->l('Example: ?tr=tracking_test&source=tracking@source.com&popup=1'),
|
|
'name' => 'FLUXCATALOG_TRACKING',
|
|
'size' => 100,
|
|
'required' => false
|
|
),
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Enregistrer'),
|
|
'name' => 'submitConfigure',
|
|
'class' => 'button'
|
|
)
|
|
);
|
|
|
|
|
|
$helper = new HelperForm();
|
|
|
|
// Module, token and currentIndex
|
|
$helper->module = $this;
|
|
$helper->name_controller = $this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
|
|
// Language
|
|
$helper->default_form_language = $default_lang;
|
|
$helper->allow_employee_form_lang = $default_lang;
|
|
|
|
// Title and toolbar
|
|
$helper->title = $this->displayName;
|
|
$helper->show_toolbar = false; // false -> remove toolbar
|
|
$helper->toolbar_scroll = false; // yes - > Toolbar is always visible on the top of the screen.
|
|
$helper->submit_action = 'submit'.$this->name;
|
|
$helper->toolbar_btn = array();
|
|
|
|
// Load current value
|
|
$helper->fields_value['FLUXCATALOG_TRACKING'] = Configuration::get('FLUXCATALOG_TRACKING');
|
|
|
|
return $helper->generateForm($fields_form);
|
|
}
|
|
|
|
}
|