876 lines
26 KiB
PHP
Executable File
876 lines
26 KiB
PHP
Executable File
<?php
|
|
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
include_once(dirname(__FILE__) . '/models/ExtraTabModel.php');
|
|
include_once(dirname(__FILE__) . '/models/ManufacturerExtraTabModel.php');
|
|
include_once(dirname(__FILE__) . '/models/ProductExtraTabModel.php');
|
|
|
|
class ExtraTabs extends Module
|
|
{
|
|
private $_html;
|
|
private $_display;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'extratabs';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '1.0.0';
|
|
$this->author = 'Antadis';
|
|
$this->need_instance = 0;
|
|
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
|
|
$this->_defaultOrderBy = 'position';
|
|
$this->displayName = $this->l('Extra tabs');
|
|
$this->description = $this->l('Adds wysiwyg extra tabs.');
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (!parent::install()
|
|
|| !$this->registerHook('header')
|
|
|| !$this->registerHook('displayManufacturerTabs')
|
|
|| !$this->registerHook('displayAdminProductsExtra')
|
|
|| !$this->registerHook('displayProductTab')
|
|
|| !$this->registerHook('displayProductTabContent')
|
|
|| !$this->registerHook('actionAdminControllerSetMedia')
|
|
|| !ExtraTabModel::createTables()
|
|
|| !ManufacturerExtraTabModel::createTables()
|
|
|| !ProductExtraTabModel::createTables()
|
|
)
|
|
return false;
|
|
|
|
$this->_clearCache('manufaturertabs.tpl');
|
|
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
$this->_clearCache('manufacturertabs.tpl');
|
|
if (!parent::uninstall() ||
|
|
!ExtraTabModel::DropTables() ||
|
|
!ProductExtraTabModel::DropTables()
|
|
|
|
)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public function initToolbar()
|
|
{
|
|
$current_index = AdminController::$currentIndex;
|
|
$token = Tools::getAdminTokenLite('AdminModules');
|
|
$back = Tools::safeOutput(Tools::getValue('back', ''));
|
|
if (!isset($back) || empty($back))
|
|
$back = $current_index.'&configure='.$this->name.'&token='.$token;
|
|
|
|
switch ($this->_display)
|
|
{
|
|
case 'add':
|
|
$this->toolbar_btn['cancel'] = array(
|
|
'href' => $back,
|
|
'desc' => $this->l('Cancel')
|
|
);
|
|
break;
|
|
case 'edit':
|
|
$this->toolbar_btn['cancel'] = array(
|
|
'href' => $back,
|
|
'desc' => $this->l('Cancel')
|
|
);
|
|
break;
|
|
case 'index':
|
|
$this->toolbar_btn['new'] = array(
|
|
'href' => $current_index.'&configure='.$this->name.'&token='.$token.'&add'.$this->name,
|
|
'desc' => $this->l('Add new')
|
|
);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return $this->toolbar_btn;
|
|
}
|
|
|
|
protected function displayList()
|
|
{
|
|
$this->context->controller->addJqueryPlugin('tablednd');
|
|
$this->context->controller->addJS(_PS_JS_DIR_.'admin-dnd.js');
|
|
|
|
$content = ExtraTabModel::getTabsListStatic((int)$this->context->language->id);
|
|
$this->fields_list = array(
|
|
'id_extratab' => array(
|
|
'title' => $this->l('Tab ID'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
'name' => array(
|
|
'title' => $this->l('Tab name'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
'associate' => array(
|
|
'title' => $this->l('Table'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
'position' => array(
|
|
'title' => $this->l('Position'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
),
|
|
);
|
|
|
|
if (Shop::isFeatureActive())
|
|
$this->fields_list['id_shop'] = array(
|
|
'title' => $this->l('Shop ID'),
|
|
'align' => 'center',
|
|
'width' => 25,
|
|
'type' => 'int',
|
|
'search' => false
|
|
);
|
|
|
|
$helper = new HelperList();
|
|
$helper->shopLinkType = '';
|
|
$helper->simple_header = false;
|
|
$helper->orderBy = 'position';
|
|
$helper->identifier = 'id_extratab';
|
|
$helper->actions = array('edit', 'delete');
|
|
$helper->show_toolbar = true;
|
|
$helper->imageType = 'jpg';
|
|
$helper->toolbar_btn['new'] = array(
|
|
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
|
|
'desc' => $this->l('Add new')
|
|
);
|
|
|
|
$helper->title = $this->displayName;
|
|
$helper->table = $this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
|
|
$this->_html .= $helper->generateList($content, $this->fields_list);
|
|
}
|
|
|
|
|
|
protected function displayAssociationTabs($id_product = null){
|
|
|
|
$token = Tools::getAdminTokenLite('AdminModules');
|
|
if ( !$id_product ){
|
|
$tabsList = $this->getTabAssociationType();
|
|
$redirect = AdminController::$currentIndex.'&configure='.$this->name;
|
|
}
|
|
else{
|
|
$tabsList = $this->getProductTabAssociationType();
|
|
$redirect = $this->adminProductRedirect = 'index.php?controller=AdminModules&configure='.$this->name.'&id_product='.(int)Tools::getValue('id_product');
|
|
}
|
|
|
|
|
|
foreach ($tabsList as $asso_name => $association) {
|
|
$object = $association['obj'];
|
|
if ( (int)$id_product )
|
|
$content = $object->getTabsList((int)$id_product, (int)$this->context->language->id);
|
|
else
|
|
$content = $object->getTabsList((int)$this->context->language->id);
|
|
$this->fields_list = array(
|
|
$association['identifier'] => array(
|
|
'title' => $this->l('Tab ID'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
$association['associate'] => array(
|
|
'title' => $this->l('Name'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
// 'associate' => array(
|
|
// 'title' => $this->l('Table'),
|
|
// 'type' => 'text',
|
|
// 'search' => false,
|
|
// 'orderby' => false,
|
|
// ),
|
|
'extratab' => array(
|
|
'title' => $this->l('Tab name'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
$association['associate'] => array(
|
|
'title' => $association['associate'],
|
|
'type' => 'text',
|
|
'search' => false,
|
|
'orderby' => false,
|
|
),
|
|
'position' => array(
|
|
'title' => $this->l('Position'),
|
|
'type' => 'text',
|
|
'search' => false,
|
|
)
|
|
);
|
|
|
|
if (Shop::isFeatureActive())
|
|
$this->fields_list['id_shop'] = array(
|
|
'title' => $this->l('Shop ID'),
|
|
'align' => 'center',
|
|
'width' => 25,
|
|
'type' => 'int',
|
|
'search' => false
|
|
);
|
|
|
|
$helper = new HelperList();
|
|
$helper->shopLinkType = '';
|
|
$helper->simple_header = false;
|
|
$helper->orderBy = 'position';
|
|
$helper->identifier = $association['identifier'];
|
|
$helper->actions = array('edit', 'delete');
|
|
$helper->show_toolbar = true;
|
|
$helper->imageType = 'jpg';
|
|
$helper->toolbar_btn['new'] = array(
|
|
'href' => $redirect.'&add'.$association['table'].'&token='.$token,
|
|
'desc' => $this->l('Add new')
|
|
);
|
|
|
|
$helper->title = $association['table'];
|
|
$helper->table = $association['table'];
|
|
$helper->token = $token;
|
|
$helper->currentIndex = $redirect;
|
|
|
|
$this->_html .= $helper->generateList($content, $this->fields_list);
|
|
}
|
|
}
|
|
|
|
|
|
protected function displayAddForm()
|
|
{
|
|
$token = Tools::getAdminTokenLite('AdminModules');
|
|
$back = Tools::safeOutput(Tools::getValue('back', ''));
|
|
$current_index = AdminController::$currentIndex;
|
|
if (!isset($back) || empty($back))
|
|
$back = $current_index.'&configure='.$this->name.'&token='.$token;
|
|
|
|
if (Tools::isSubmit('update'.$this->name) && Tools::getValue('id_extratab'))
|
|
{
|
|
$this->_display = 'edit';
|
|
$id_extratab = (int)Tools::getValue('id_extratab');
|
|
$extraTabs = new ExtraTabModel((int)$id_extratab);
|
|
}
|
|
else
|
|
$this->_display = 'add';
|
|
|
|
$associations = array(
|
|
array(
|
|
'identifier' => 'product',
|
|
'name' => $this->l('Product')
|
|
),
|
|
array(
|
|
'identifier' => 'manufacturer',
|
|
'name' => $this->l('Manufacturer')
|
|
),
|
|
);
|
|
|
|
$this->fields_form[0]['form'] = array(
|
|
'tinymce' => true,
|
|
'legend' => array(
|
|
'title' => isset($extraTabs) ? $this->l('Edit the Extra tab.') : $this->l('New Extra tab'),
|
|
'icon' => isset($extraTabs) ? 'icon-edit' : 'icon-plus-square'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Name'),
|
|
'name' => 'name',
|
|
'lang' => true
|
|
),
|
|
// array(
|
|
// 'type' => 'textarea',
|
|
// 'label' => $this->l('Description'),
|
|
// 'name' => 'description',
|
|
// 'lang' => true,
|
|
// 'autoload_rte' => true
|
|
// ),
|
|
// array(
|
|
// 'type' => 'text',
|
|
// 'label' => $this->l('Table'),
|
|
// 'name' => 'associate',
|
|
// 'required' => true,
|
|
// ),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Table'),
|
|
'name' => 'associate',
|
|
'required' => true,
|
|
'options' => array(
|
|
'query' => $associations,
|
|
'id' => 'identifier',
|
|
'name' => 'name'
|
|
)
|
|
)
|
|
),
|
|
'buttons' => array(
|
|
'cancelBlock' => array(
|
|
'title' => $this->l('Cancel'),
|
|
'href' => $back,
|
|
'icon' => 'process-icon-cancel'
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'name' => 'submit'.$this->name,
|
|
'title' => $this->l('Save'),
|
|
)
|
|
);
|
|
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
if ( $this->_display == 'edit' ){
|
|
$this->fields_value['name'][$language['id_lang']] = $extraTabs->name[$language['id_lang']];
|
|
$this->fields_value['description'][$language['id_lang']] = $extraTabs->description[$language['id_lang']];
|
|
}
|
|
else{
|
|
$this->fields_value['name'][$language['id_lang']] = '';
|
|
$this->fields_value['description'][$language['id_lang']] = '';
|
|
}
|
|
}
|
|
if ( $this->_display == 'edit' ){
|
|
$this->fields_value['associate'] = $extraTabs->associate;
|
|
}
|
|
else{
|
|
$this->fields_value['associate'] = '';
|
|
}
|
|
|
|
$helper = $this->initForm();
|
|
|
|
if (isset($id_extratab))
|
|
{
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&id_extratab='.$id_extratab;
|
|
$helper->submit_action = 'update'.$this->name;
|
|
}
|
|
else
|
|
$helper->submit_action = 'add'.$this->name;
|
|
|
|
$helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
|
|
$this->_html .= $helper->generateForm($this->fields_form);
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
protected function displayAddAssociationForm($asso_name, $association, $id_product = null, $id_manufacturer = null){
|
|
$token = Tools::getAdminTokenLite('AdminModules');
|
|
$back = Tools::safeOutput(Tools::getValue('back', ''));
|
|
$current_index = AdminController::$currentIndex;
|
|
if (!isset($back) || empty($back))
|
|
$back = $current_index.'&configure='.$this->name.'&token='.$token;
|
|
|
|
if (Tools::isSubmit('update'.$association['table']) && Tools::getValue($association['identifier']))
|
|
{
|
|
$this->_display = 'edit';
|
|
$identifier = (int)Tools::getValue($association['identifier']);
|
|
$obj = $association['obj'];
|
|
$extraTabs = new $obj((int)$identifier);
|
|
}
|
|
else
|
|
$this->_display = 'add';
|
|
|
|
|
|
if ( $id_product ){
|
|
$maxPosition = ProductExtraTabModel::getMaxPosition((int)$id_product);
|
|
// if ( $this->_display == 'edit' )
|
|
// $maxPosition--;
|
|
|
|
$positions = array();
|
|
for ($i=1; $i<=$maxPosition; $i++){
|
|
$positions[] = array(
|
|
'position' => $i
|
|
);
|
|
}
|
|
}else if ( $id_manufacturer ){
|
|
$maxPosition = ProductExtraTabModel::getMaxPosition((int)$id_manufacturer);
|
|
if ( $this->_display == 'edit' )
|
|
$maxPosition--;
|
|
|
|
$positions = array();
|
|
for ($i=0; $i<=$maxPosition; $i++){
|
|
$positions[] = array(
|
|
'position' => $i
|
|
);
|
|
}
|
|
|
|
} else{
|
|
$positions = array();
|
|
$positions[] = array(
|
|
'position' => 0
|
|
);
|
|
}
|
|
|
|
$extraTables = ExtraTabModel::getExtraTabsByAssociation($asso_name, true);
|
|
$this->fields_form[0]['form'] = array(
|
|
'tinymce' => true,
|
|
'legend' => array(
|
|
'title' => (isset($extraTabs) ? $this->l('Edit the Extra tab.') : $this->l('New Extra tab')).' ('.$asso_name.')',
|
|
'icon' => isset($extraTabs) ? 'icon-edit' : 'icon-plus-square'
|
|
),
|
|
'input' => array(
|
|
// array(
|
|
// 'type' => 'text',
|
|
// 'label' => $this->l('Title'),
|
|
// 'name' => 'name',
|
|
// 'lang' => true
|
|
// ),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->l('Content'),
|
|
'name' => 'content',
|
|
'lang' => true,
|
|
'autoload_rte' => true
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Tab'),
|
|
'name' => 'id_extratab',
|
|
'required' => true,
|
|
'options' => array(
|
|
'query' => $extraTables,
|
|
'id' => 'id_extratab',
|
|
'name' => 'name'
|
|
)
|
|
),
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Position'),
|
|
'name' => 'position',
|
|
'required' => true,
|
|
'options' => array(
|
|
'query' => $positions,
|
|
'id' => 'position',
|
|
'name' => 'position'
|
|
)
|
|
),
|
|
|
|
),
|
|
'buttons' => array(
|
|
'cancelBlock' => array(
|
|
'title' => $this->l('Cancel'),
|
|
'href' => $back,
|
|
'icon' => 'process-icon-cancel'
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'name' => 'submit'.$this->name,
|
|
'title' => $this->l('Save'),
|
|
)
|
|
);
|
|
|
|
if ( !$id_product ){
|
|
$this->fields_form[0]['form']['input'][] = array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Item'),
|
|
'name' => $association['primary'],
|
|
'required' => true,
|
|
'options' => array(
|
|
'query' => $association['options'],
|
|
'id' => $association['primary'],
|
|
'name' => 'name'
|
|
)
|
|
);
|
|
}
|
|
else{
|
|
$this->fields_form[0]['form']['input'][] = array(
|
|
'type' => 'hidden',
|
|
'label' => $this->l('Item'),
|
|
'name' => $association['primary'],
|
|
'required' => true,
|
|
);
|
|
}
|
|
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
if ( $this->_display == 'edit' ){
|
|
$this->fields_value['name'][$language['id_lang']] = $extraTabs->title[$language['id_lang']];
|
|
$this->fields_value['content'][$language['id_lang']] = $extraTabs->content[$language['id_lang']];
|
|
}
|
|
else{
|
|
$this->fields_value['name'][$language['id_lang']] = '';
|
|
$this->fields_value['content'][$language['id_lang']] = '';
|
|
}
|
|
}
|
|
if ( $this->_display == 'edit' ){
|
|
$this->fields_value[$association['primary']] = $extraTabs->{$association['primary']};
|
|
$this->fields_value['id_extratab'] = $extraTabs->id_extratab;
|
|
$this->fields_value['position'] = $extraTabs->position;
|
|
}
|
|
else{
|
|
$this->fields_value[$association['primary']] = 0;
|
|
$this->fields_value['id_extratab'] = 0;
|
|
$this->fields_value['position'] = $maxPosition;
|
|
}
|
|
|
|
if ( $id_product )
|
|
$this->fields_value[$association['primary']] = (int)$id_product;
|
|
|
|
$helper = $this->initForm();
|
|
|
|
if (isset($identifier))
|
|
{
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&'.$association['identifier'].'='.$identifier;
|
|
$helper->submit_action = 'update'.$association['table'];
|
|
}
|
|
else
|
|
$helper->submit_action = 'add'.$association['table'];
|
|
|
|
$helper->fields_value = isset($this->fields_value) ? $this->fields_value : array();
|
|
$this->_html .= $helper->generateForm($this->fields_form);
|
|
|
|
return;
|
|
}
|
|
|
|
public function getTabAssociationType(){
|
|
return array(
|
|
'manufacturer' => array(
|
|
'obj' => new ManufacturerExtraTabModel(),
|
|
'identifier' => 'id_manufacturer_extratab',
|
|
'table' => 'manufacturer_extratab',
|
|
'associate' => 'manufacturer',
|
|
'primary' => 'id_manufacturer',
|
|
'options' => Manufacturer::getManufacturers(),
|
|
'lang' => true
|
|
),
|
|
);
|
|
}
|
|
|
|
public function getProductTabAssociationType(){
|
|
return array(
|
|
'product' => array(
|
|
'obj' => new ProductExtraTabModel(),
|
|
'identifier' => 'id_product_extratab',
|
|
'table' => 'product_extratab',
|
|
'associate' => 'product',
|
|
'primary' => 'id_product',
|
|
'options' => false,
|
|
'lang' => true
|
|
),
|
|
);
|
|
}
|
|
|
|
private function initForm()
|
|
{
|
|
$helper = new HelperForm();
|
|
|
|
$helper->module = $this;
|
|
$helper->name_controller = 'extratabs';
|
|
$helper->identifier = $this->identifier;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->languages = $this->context->controller->_languages;
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
$helper->default_form_language = $this->context->controller->default_form_language;
|
|
$helper->allow_employee_form_lang = $this->context->controller->allow_employee_form_lang;
|
|
$helper->toolbar_scroll = true;
|
|
$helper->toolbar_btn = $this->initToolbar();
|
|
|
|
return $helper;
|
|
}
|
|
|
|
protected function _postValidation()
|
|
{
|
|
$this->_errors = array();
|
|
|
|
if (Tools::isSubmit('submit'.$this->name))
|
|
{
|
|
$this->context->controller->getLanguages();
|
|
}
|
|
if (count($this->_errors))
|
|
{
|
|
foreach ($this->_errors as $err)
|
|
$this->_html .= '<div class="alert alert-danger">'.$err.'</div>';
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private function _postProcess()
|
|
{
|
|
if (Tools::isSubmit('updatePositions'))
|
|
$this->updatePositionsDnd();
|
|
if ($this->_postValidation() == false)
|
|
return false;
|
|
|
|
$this->_clearCache('manufacturertabs.tpl');
|
|
|
|
$this->_errors = array();
|
|
if (Tools::isSubmit('submit'.$this->name))
|
|
$this->processSubmit();
|
|
elseif (Tools::isSubmit('delete'.$this->name) && Tools::getValue('id_extratabs'))
|
|
$this->processDelete();
|
|
if (count($this->_errors))
|
|
{
|
|
foreach ($this->_errors as $err)
|
|
$this->_html .= '<div class="alert error">'.$err.'</div>';
|
|
}
|
|
}
|
|
|
|
public function processSubmit(){
|
|
if (Tools::isSubmit('add'.$this->name))
|
|
$this->processSubmitAdd();
|
|
elseif (Tools::isSubmit('update'.$this->name))
|
|
$this->processEdit();
|
|
else{
|
|
$associations = $this->getTabAssociationType();
|
|
foreach ($associations as $asso_name => $association) {
|
|
if ( Tools::isSubmit('add'.$association['table']) )
|
|
$this->processSubmitAddAsso($asso_name, $association);
|
|
elseif ( Tools::isSubmit('update'.$association['table']) )
|
|
$this->processEditAsso($asso_name, $association);
|
|
elseif ( Tools::isSubmit('delete'.$association['table']) )
|
|
$this->processSubmitDeleteAsso($asso_name, $association);
|
|
}
|
|
$productAssociations = $this->getProductTabAssociationType();
|
|
foreach ($productAssociations as $asso_name => $association) {
|
|
if ( Tools::isSubmit('add'.$association['table']) )
|
|
$this->processSubmitAddAsso($asso_name, $association);
|
|
elseif ( Tools::isSubmit('update'.$association['table']) )
|
|
$this->processEditAsso($asso_name, $association);
|
|
elseif ( Tools::isSubmit('delete'.$association['table']) )
|
|
$this->processDeleteAsso($asso_name, $association);
|
|
}
|
|
}
|
|
|
|
if ( Tools::getValue('id_product') )
|
|
Tools::redirectAdmin('index.php?controller=AdminProducts&id_product='.(int)Tools::getValue('id_product').'&updateproduct&key_tab=ModuleExtratabs&&token='.Tools::getAdminTokenLite('AdminProducts'));
|
|
else
|
|
Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&'.$this->redirect);
|
|
}
|
|
|
|
public function processDelete(){
|
|
}
|
|
|
|
public function processSubmitAdd(){
|
|
|
|
$this->redirect = 'add'.$this->name.'Confirmation';
|
|
|
|
$extraTabs = new ExtraTabModel();
|
|
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
$extraTabs->name[$language['id_lang']] = Tools::getValue('name_'.$language['id_lang']);
|
|
$extraTabs->description[$language['id_lang']] = Tools::getValue('description_'.$language['id_lang']);
|
|
}
|
|
$extraTabs->associate = Tools::getValue('associate');
|
|
$extraTabs->position = ExtraTabModel::getMaxPosition();
|
|
|
|
return $extraTabs->add();
|
|
}
|
|
|
|
public function processEdit(){
|
|
|
|
$this->redirect = 'update'.$this->name.'Confirmation';
|
|
|
|
$id_extratab = Tools::getvalue('id_extratab');
|
|
$extraTabs = new ExtraTabModel((int)$id_extratab);
|
|
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
$extraTabs->name[$language['id_lang']] = Tools::getValue('name_'.$language['id_lang']);
|
|
$extraTabs->description[$language['id_lang']] = Tools::getValue('description_'.$language['id_lang']);
|
|
}
|
|
$extraTabs->associate = Tools::getValue('associate');
|
|
return $extraTabs->save();
|
|
}
|
|
|
|
|
|
public function processSubmitAddAsso($asso_name, $association){
|
|
$extraTabs = $association['obj'];
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
$extraTabs->title[$language['id_lang']] = Tools::getValue('name_'.$language['id_lang']);
|
|
$extraTabs->content[$language['id_lang']] = Tools::getValue('content_'.$language['id_lang']);
|
|
}
|
|
$extraTabs->{$association['primary']} = Tools::getValue($association['primary']);
|
|
$extraTabs->id_extratab = Tools::getValue('id_extratab');
|
|
$extraTabs->position = Tools::getValue('position');
|
|
|
|
return $extraTabs->add();
|
|
}
|
|
|
|
public function processEditAsso($asso_name, $association){
|
|
$this->redirect = 'update'.$association['table'].'Confirmation';
|
|
|
|
$id_extratab = Tools::getvalue($association['identifier']);
|
|
|
|
$obj = $association['obj'];
|
|
$extraTabs = new $obj((int)$id_extratab);
|
|
|
|
$extraTabs = new $association['obj']((int)$id_extratab);
|
|
|
|
$this->context->controller->getLanguages();
|
|
foreach ($this->context->controller->_languages as $language)
|
|
{
|
|
$extraTabs->title[$language['id_lang']] = Tools::getValue('name_'.$language['id_lang']);
|
|
$extraTabs->content[$language['id_lang']] = Tools::getValue('content_'.$language['id_lang']);
|
|
}
|
|
$extraTabs->{$association['primary']} = Tools::getValue($association['primary']);
|
|
$extraTabs->id_extratab = Tools::getValue('id_extratab');
|
|
|
|
$extraTabs->updatePosition();
|
|
return $extraTabs->save();
|
|
}
|
|
|
|
|
|
public function processDeleteAsso($asso_name, $association){
|
|
|
|
$id_extratab = Tools::getvalue($association['identifier']);
|
|
|
|
$obj = $association['obj'];
|
|
$extraTabs = new $obj((int)$id_extratab);
|
|
|
|
$extraTabs->delete();
|
|
|
|
if ( Tools::getValue('id_product') )
|
|
Tools::redirectAdmin('index.php?controller=AdminProducts&id_product='.(int)Tools::getValue('id_product').'&updateproduct&key_tab=ModuleExtratabs&token='.Tools::getAdminTokenLite('AdminProducts'));
|
|
else
|
|
Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&'.$this->redirect);
|
|
|
|
}
|
|
|
|
|
|
public function getContent()
|
|
{
|
|
$this->_html = '';
|
|
$this->_postProcess();
|
|
|
|
$displayList = true;
|
|
if (Tools::isSubmit('add'.$this->name) || Tools::isSubmit('update'.$this->name)){
|
|
$this->displayAddForm();
|
|
$displayList = false;
|
|
}
|
|
else{
|
|
$associations = $this->getTabAssociationType();
|
|
foreach ($associations as $asso_name => $association) {
|
|
if ( Tools::isSubmit('add'.$association['table']) || Tools::isSubmit('update'.$association['table']) ){
|
|
$displayList = false;
|
|
$this->displayAddAssociationForm($asso_name, $association);
|
|
}
|
|
elseif( Tools::isSubmit('delete'.$association['table']) ){
|
|
$this->processDeleteAsso($asso_name, $association);
|
|
}
|
|
}
|
|
$productAssociations = $this->getProductTabAssociationType();
|
|
foreach ($productAssociations as $asso_name => $association) {
|
|
if ( ( Tools::isSubmit('add'.$association['table']) || Tools::isSubmit('update'.$association['table']) ) && Tools::getValue('id_product') ){
|
|
$displayList = false;
|
|
$this->displayAddAssociationForm($asso_name, $association, (int)Tools::getValue('id_product'));
|
|
}
|
|
elseif( Tools::isSubmit('delete'.$association['table']) ){
|
|
$this->processDeleteAsso($asso_name, $association);
|
|
}
|
|
}
|
|
}
|
|
if ( $displayList ){
|
|
$this->displayList();
|
|
$this->displayAssociationTabs();
|
|
}
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
/**
|
|
* ===============================
|
|
* HOOKS
|
|
*/
|
|
|
|
public function hookActionAdminControllerSetMedia($params){
|
|
// add javascript to products back office
|
|
if($this->context->controller->controller_name == 'AdminProducts' && Tools::getValue('id_product') /*&& Tools::getValue('action') == 'ModuleExtratabs'*/ ) {
|
|
$this->context->controller->addJS(_PS_MODULE_DIR_.'extratabs/js/adminProduct.js');
|
|
}
|
|
|
|
}
|
|
|
|
public function hookDisplayAdminProductsExtra($params){
|
|
$this->displayAssociationTabs(Tools::getValue('id_product'));
|
|
return $this->_html;
|
|
}
|
|
|
|
public function hookDisplayProductTab($params){
|
|
if ( !Tools::getValue('id_product') )
|
|
return false;
|
|
$extraTabs = ProductExtraTabModel::getByProductID((int)Tools::getValue('id_product'), $params['cart']->id_lang);
|
|
$this->smarty->assign('extraTabs', $extraTabs);
|
|
$this->smarty->assign('features', $params['product']->getFrontFeatures($this->context->language->id));
|
|
|
|
return $this->display(__FILE__, 'productextratabs_tab.tpl');
|
|
}
|
|
public function hookDisplayProductTabContent($params){
|
|
if ( !Tools::getValue('id_product') )
|
|
return false;
|
|
// $extraTabs = ProductExtraTabModel::getByProductID((int)Tools::getValue('id_product'), $params['cart']->id_lang);
|
|
$extraTabs = ProductExtraTabModel::getByProductID((int)Tools::getValue('id_product'), $params['cart']->id_lang);
|
|
$this->smarty->assign('extraTabs', $extraTabs);
|
|
|
|
// antadis 13142 - when imported by csv, description is not embedded as paragraphs. But it is embedded as paragraph when
|
|
// saving product in BO. So ensure description is embedded here.
|
|
if (!empty($params['product']->description)) {
|
|
$params['product']->description = '<p>'.preg_replace(array('/^<p>/i', '/<\/p>$/i'), '', $params['product']->description).'</p>';
|
|
}
|
|
|
|
$this->smarty->assign('product', $params['product']);
|
|
$this->smarty->assign('privatesale', $params['privatesale']);
|
|
return $this->display(__FILE__, 'productextratabs_tabcontent.tpl');
|
|
}
|
|
|
|
public function hookDisplayManufacturerTabs($params){
|
|
if ( !Tools::getValue('id_manufacturer') )
|
|
return false;
|
|
$extraTabs = ManufacturerExtraTabModel::getByManufacturerID((int)Tools::getValue('id_manufacturer'), $params['cart']->id_lang);
|
|
$this->smarty->assign(array(
|
|
'extraTabs' => $extraTabs,
|
|
));
|
|
return $this->display(__FILE__, 'manufacturertabs.tpl');
|
|
}
|
|
|
|
public function updatePositions(){
|
|
echo 'updatePosition'."\r\n";
|
|
|
|
}
|
|
|
|
public function ajaxProcessUpdatePositions()
|
|
{
|
|
$way = (int)(Tools::getValue('way'));
|
|
$id_extratab = (int)(Tools::getValue('id'));
|
|
$positions = Tools::getValue('extratab');
|
|
|
|
if (is_array($positions)){
|
|
foreach ($positions as $position => $value)
|
|
{
|
|
$pos = explode('_', $value);
|
|
|
|
if (isset($pos[2]) && (int)$pos[2] === $id_extratab)
|
|
{
|
|
if ($extratab = new ExtraTabModel((int)$pos[2]))
|
|
if (isset($position) && $extratab->updatePosition($way, $position+1))
|
|
{
|
|
echo 'ok position '.(int)$position.' for extratab '.(int)$pos[2]."\r\n";
|
|
}
|
|
else
|
|
echo '{"hasError" : true, "errors" : "Can not update extratab '.(int)$id_extratab.' to position '.(int)$position.' "}';
|
|
else
|
|
echo '{"hasError" : true, "errors" : "This extratab ('.(int)$id_extratab.') can t be loaded"}';
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|