* @copyright 2011-2018 PresTeamShop * @license see file: LICENSE.txt * @category PrestaShop * @category Module * @revision 56 */ if (!defined('_PS_VERSION_')) { exit; } require_once _PS_MODULE_DIR_.'/productextratabs/classes/ProductExtraTabsCore.php'; require_once _PS_MODULE_DIR_.'/productextratabs/classes/PETTabClass.php'; require_once _PS_MODULE_DIR_.'/productextratabs/classes/PETTabContentClass.php'; class ProductExtraTabs extends Module { const VERSION = '1.1.2'; const HOOK_DISPLAY_REASSURANCE = 'hook_display_reassurance'; const HOOK_CUSTOM = 'custom'; const HOOK_PRODUCT_FOOTER = 'hook_product_footer'; const HOOK_PRODUCT_TAB = 'hook_display_product_extra_content'; /* tab type */ const CONTACT = 'contact'; const CONTENT = 'content'; const COMBINATION = 'combination'; public $pet_hook_position; public $core; public $errors = array(); public $warnings = array(); public $html = ''; public $prefix_module; public $params_back; public $override_css; public $override_js; public $translations_path; protected $smarty; protected $cookie; public $globals = array(); public $config_vars = array(); public $configure_vars = array( array('name' => 'PET_VERSION', 'default_value' => self::VERSION, 'is_html' => false), array('name' => 'PET_HOOK', 'default_value' => 'hook_display_reassurance', 'is_html' => false), array('name' => 'PET_STYLE_TABS', 'default_value' => 'tab_horizontal', 'is_html' => false), array('name' => 'PET_OVERRIDE_CSS', 'default_value' => '', 'is_html' => true), array('name' => 'PET_OVERRIDE_JS', 'default_value' => '', 'is_html' => true), array('name' => 'PET_ENABLE_DEBUG', 'default_value' => '0', 'is_html' => false), array('name' => 'PET_IP_DEBUG', 'default_value' => '', 'is_html' => false), array('name' => 'PET_SHOW_EMPTY_TABS', 'default_value' => '0', 'is_html' => false), array('name' => 'PET_ORDER_TABS', 'default_value' => 'native_first', 'is_html' => false), array( 'name' => 'PET_IGNORE_SELECTORS', 'default_value' => '.pts_content_ifeedback_products', 'is_html' => false ), array('name' => 'PET_BG_COLOR_TABS', 'default_value' => '', 'is_html' => false), array('name' => 'PET_FONT_COLOR_TABS', 'default_value' => '', 'is_html' => false), array('name' => 'PET_BG_COLOR_SLTED_TABS', 'default_value' => '', 'is_html' => false), array('name' => 'PET_FONT_COLOR_SLTED_TABS', 'default_value' => '', 'is_html' => false), ); public function __construct() { $this->prefix_module = 'PET'; $this->name = 'productextratabs'; $this->tab = 'front_office_features'; $this->version = '1.1.2'; $this->author = 'PresTeamShop'; $this->bootstrap = true; $this->module_key = '43550bce1a137e05171febc9be92b922'; $this->author_address = '0x91C5d6F1c2ADb4eE96da147F3Fa4aD164F874a15'; parent::__construct(); $this->errors = array(); $this->warnings = array(); $this->params_back = array(); $this->globals = new stdClass(); $this->core = new ProductExtraTabsCore($this, $this->context); $this->name_file = Tools::substr(basename(__FILE__), 0, Tools::strlen(basename(__FILE__)) - 4); $this->displayName = 'Product Extra Tabs'; $this->description = $this->l('Add additional tabs to their products to provide more relevant information details'); $this->confirmUninstall = $this->l('Are you sure you want uninstall ?', $this->name_file); $this->globals_smarty = array( 'tab_type' => array( array('value' => self::CONTENT, 'text' => $this->l('Content')), array('value' => self::CONTACT, 'text' => $this->l('Form contact')), array('value' => self::COMBINATION, 'text' => $this->l('Content by product combination')) ), 'content_type_tabs' => array( array('value' => 'supplier', 'text' => $this->l('Supplier')), array('value' => 'category', 'text' => $this->l('Category')), array('value' => 'manufacturer', 'text' => $this->l('Manufacturer')), array('value' => 'feature', 'text' => $this->l('Feature')) ) ); $this->pet_hook_position = Configuration::get('PET_HOOK'); $this->core->checkModulePTS(); if (!function_exists('curl_init') && !function_exists('curl_setopt') && !function_exists('curl_exec') && !function_exists('curl_close') ) { $this->errors[] = $this->l('CURL functions not available for registration module.', $this->name_file); } } public function install() { if (!parent::install() || !$this->core->install() || !$this->registerHook('header') || !$this->registerHook('displayFooterProduct') || !$this->registerHook('productExtraTabs') || !$this->registerHook('productContent') || !$this->registerHook('displayReassurance') || !$this->registerHook('displayAdminProductsExtra') || !$this->registerHook('displayProductExtraContent') || !$this->registerHook('actionAdminControllerSetMedia') || !$this->registerHook('actionProductUpdate')) { return false; } Configuration::updateValue('PET_STYLE_TABS', 'tab_horizontal', false); return true; } public function uninstall() { if (!parent::uninstall() || !$this->core->uninstall()) { return false; } return true; } public function getContent() { $registered_version = Configuration::get($this->prefix_module.'_VERSION'); if ($registered_version == $this->version) { $forms = $this->getHelperForm(); if (is_array($forms) && count($forms) && isset($forms['forms']) && is_array($forms['forms']) && count($forms['forms']) ) { foreach ($forms['forms'] as $key => $form) { if (Tools::isSubmit('form-'.$key)) { $this->smarty->assign('CURRENT_FORM', $key); //save form data in configuration $this->core->saveFormData($form); //show message $this->smarty->assign('show_saved_message', true); break; } } } } $this->displayForm(); return $this->html; } protected function displayForm() { //update version module //--------------------------------------------------------------------------- $registered_version = Configuration::get($this->prefix_module.'_VERSION'); if ($registered_version != $this->version) { $this->core->installTab(); $this->context->controller->addJS($this->_path.'views/js/admin/update_version.js'); $this->smarty->assign(array( 'module_name' => $this->displayName, 'module_version' => $this->version, )); Media::addJsDef(array( 'token' => Tools::encrypt($this->name.'/index'), 'url_call' => $this->context->link->getAdminLink('AdminActions'.$this->prefix_module) )); $this->html = $this->display(__FILE__, 'views/templates/admin/update_version.tpl'); return; } //--------------------------------------------------------------------------- $this->context->controller->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js'); $this->context->controller->addJS(_PS_JS_DIR_.'admin/tinymce.inc.js'); $this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.tablednd.js'); $this->context->controller->addJS( $this->_path.'views/js/lib/bootstrap/plugins/colorpicker/bootstrap-colorpicker.js' ); $this->context->controller->addJS( $this->_path.'views/js/lib/jquery/plugins/jquery.tokenize/jquery.tokenize.js' ); $this->context->controller->addCSS( $this->_path.'views/css/lib/bootstrap/plugins/colorpicker/bootstrap-colorpicker.css' ); $this->context->controller->addCSS( $this->_path.'views/css/lib/jquery/plugins/jquery.tokenize/jquery.tokenize.css' ); $this->getTemplateVarsBackOffice($this->params_back); Media::addJsDef(array( 'url_contact_addons' => 'https://addons.prestashop.com/en/write-to-developper?id_product=4892', 'url_opinions_addons' => 'http://addons.prestashop.com/ratings.php', )); $this->core->displayForm(); $this->html .= $this->display(__FILE__, 'views/templates/admin/configure.tpl'); } private function getTemplateVarsBackOffice(&$template_vars) { $helper_form = $this->getHelperForm(); //extra tabs for PresTeamShop $this->getExtraTabs($helper_form); $id_lang = $this->context->employee->id_lang; $id_shop = $this->context->shop->id; //get Categories $categories = Category::getCategories($id_lang, true); $categories_li = array(); $categories_tokenize = array(); self::recurseCategory($categories_li, $categories, null); self::recurseCategory($categories_tokenize, $categories, null, false, 1, -1, $id_lang, $id_shop); $suppliers = Supplier::getSuppliers(); array_unshift($suppliers, array('id_supplier' => -1, 'name' => $this->l('All suppliers'))); $manufacturer = Manufacturer::getManufacturers(false, $id_lang, true); array_unshift($manufacturer, array('id_manufacturer' => -1, 'name' => $this->l('All manufacturers'))); /* get products */ $sql = new DbQuery(); $sql->select('count(*)'); $sql->from('product'); $sql->where('active = 1'); $total_products = Db::getInstance()->getValue($sql); $limit = 300; $total_pages = ceil((int)$total_products / (int)$limit); $products = array(); for ($page = 1; $page <= $total_pages; $page++) { $start = ($page - 1) * 300; $sql1 = new DbQuery(); $sql1->select('p.id_product, pl.name'); $sql1->from('product', 'p'); $sql1->innerJoin('product_lang', 'pl', 'pl.id_product = p.id_product'); $sql1->where('p.active = 1 AND pl.id_lang = '.(int)$id_lang.' AND pl.id_shop = '.(int)$id_shop); $sql1->orderBy('pl.id_product ASC'); $sql1->limit($limit, $start); $products[] = Db::getInstance()->executeS($sql1); } $groups = Group::getGroups($id_lang); array_unshift($groups, array('id_group' => '-1', 'name' => $this->l('All groups'))); $result_tabs = PETTabClass::getTabs(null, true, $id_lang); array_unshift($result_tabs, array('id_tab' => -1, 'name' => $this->l('-- Select an option --'))); $disable_overrides = Configuration::get('PS_DISABLE_OVERRIDES'); $massive_type_content = $this->globals_smarty['content_type_tabs']; $massive_type_content[] = array('value' => 'product', 'text' => $this->l('Products')); //$massive_type_content[] = array('value' => 'feature', 'text' => $this->l('Feature')); $features = Feature::getFeatures($id_lang); // array_unshift($features, array('id_feature' => -1, 'name' => $this->l('All features'))); $template_vars = array( 'HELPER_FORM' => $helper_form, 'GLOBALS_SMARTY' => $this->globals_smarty, 'CATEGORIES' => $categories_li, 'CATEGORIES_TOKENIZE' => $categories_tokenize, 'ID_LANGUAGE' => $this->context->employee->id_lang, 'SUPPLIERS' => $suppliers, 'MANUFACTURERS' => $manufacturer, 'FEATURE' => $features, 'FEATURES' => $features, 'GROUPS' => $groups, 'MODULE_PREFIX' => $this->prefix_module, 'BIGGER_COLS' => false, 'TABS' => $result_tabs, 'REMOTE_ADDR' => Tools::getRemoteAddr(), 'DISABLE_OVERRIDES' => $disable_overrides, 'ID_LANG' => $this->context->employee->id_lang, 'LANGUAGES' => Language::getLanguages(false), 'DEFAULT_LENGUAGE' => Configuration::get('PS_LANG_DEFAULT'), 'MASSIVE_TYPE_CONTENT' => $massive_type_content, 'PRODUCTS' => $products, 'disable_overrides' => $disable_overrides, 'Msg' => array( 'names_tab_empty' => $this->l('You must enter a tab name at least one language'), 'edit' => $this->l('Edit'), 'remove' => $this->l('Remove'), 'yes' => $this->l('Yes'), 'no' => $this->l('No'), 'all_products' => $this->l('All products'), 'all_categories' => $this->l('All categories'), 'choose_type' => $this->l('Choose a type'), 'select_product_lang' => $this->l('Select product'), 'text_search_button' => $this->l('Search'), 'add_IP' => $this->l('Add IP'), 'fields_required' => $this->l('Fill in the fields marked with an asterisk'), 'confirm_delete' => $this->l('Are you sure to delete the record?'), 'confirm_action' => $this->l('Are you sure do this?'), 'choose_tab' => $this->l('Choose a tab'), 'select_option' => $this->l('Select an option'), 'comb_required' => $this->l('You must add content for at least one combination'), 'required_value' => $this->l('The next field must not be empty') ), ); } /** * Extra tabs for PresTeamShop * @param type $helper_form */ private function getExtraTabs(&$helper_form) { $helper_form['tabs']['translate'] = array( 'label' => $this->l('Translate'), 'href' => 'translate', 'icon' => 'globe' ); $helper_form['tabs']['code_editors'] = array( 'label' => $this->l('Code Editors'), 'href' => 'code_editors', 'icon' => 'code' ); $helper_form['tabs']['another_modules'] = array( 'label' => $this->l('Another modules'), 'href' => 'another_modules', 'icon' => 'cubes', ); $helper_form['tabs']['suggestions'] = array( 'label' => $this->l('Suggestions'), 'href' => 'suggestions', 'icon' => 'pencil' ); } public function getHelperForm() { $tabs = $this->getHelperTabs(); $settings = $this->getSettingsForm(); $design = $this->getDesignForm(); $form = array( 'title' => $this->l('Menu'), 'tabs' => $tabs, 'forms' => array( 'settings' => $settings, 'design' => $design ) ); return $form; } public function getHelperTabs() { $tabs = array( 'settings' => array( 'label' => $this->l('Settings'), 'href' => 'settings', 'icon' => 'cogs' ), 'settings_of_tabs' => array( 'label' => $this->l('Settings of tabs'), 'href' => 'settings_of_tabs', 'icon' => 'bookmark-o' ), 'settings_content_tabs' => array( 'label' => $this->l('Add content tabs', $this->name_file), 'href' => 'settings_content_tabs', 'icon' => 'pencil' ), 'settings_massive_content_tab' => array( 'label' => $this->l('Add massive content tabs', $this->name_file), 'href' => 'settings_massive_content_tab', 'icon' => 'pencil-square-o' ), 'design' => array( 'label' => $this->l('Design'), 'href' => 'design', 'icon' => 'paint-brush' ) ); return $tabs; } public function getNameByTable($table, $id_table) { $table_name = $this->l('Category'); if ((int)$id_table === -1) { return array('table' => $table_name, 'name' => $this->l('All categories')); } $sql = new DbQuery(); $sql->select('name'); if ($table === 'category') { $sql->from('category_lang'); $sql->where('id_lang = '.(int)$this->context->employee->id_lang); } elseif ($table === 'product') { $sql->from('product_lang'); $sql->where('id_lang = '.(int)$this->context->employee->id_lang); $table_name = $this->l('Product'); } elseif ($table === 'feature') { $sql->from('feature_lang'); $sql->where('id_lang = '.(int)$this->context->employee->id_lang); $table_name = $this->l('Feature'); } else { $sql->from($table); if ($table === 'supplier') { $table_name = $this->l('Supplier'); } elseif ($table === 'manufacturer') { $table_name = $this->l('Manufacturer'); } } $sql->where('id_'.$table.' = '.(int)$id_table); $name = Db::getInstance()->getValue($sql); return array('table' => $table_name, 'name' => $name); } public function getSettingsContentTabsList() { $page = Tools::getValue('page', 1); $items_per_page = Tools::getValue('items_per_page', 20); $offset = ($page - 1) * $items_per_page; $data = Tools::getValue('data', array()); $data['active'] = 1; $tabs_content = PETTabContentClass::getContentTab( $this->context->employee->id_lang, $data, $items_per_page, $offset, 'tc.id_tab_content ASC' ); $total_items = count(PETTabContentClass::getContentTab( $this->context->employee->id_lang, $data )); if (!empty($tabs_content)) { foreach ($tabs_content as &$tab_content) { if ($tab_content['id_product'] === '-1' && empty($tab_content['name_product'])) { $tab_content['name_product'] = $this->l('All products'); } if ((int)$tab_content['massive'] === 1) { $id_table = explode(',', $tab_content['id_table']); $tab_content['name_id_table'] = ''; $tab_content['table'] = ''; foreach ($id_table as $id) { $param = $this->getNameByTable($tab_content['name_table'], $id); $tab_content['name_id_table'] .= $param['name'].', '; $tab_content['table'] = $param['table']; } $tab_content['name_id_table'] = trim($tab_content['name_id_table'], ', '); } else { $param = $this->getNameByTable($tab_content['name_table'], $tab_content['id_table']); $tab_content['name_id_table'] = $param['name']; $tab_content['table'] = $param['table']; if ($tab_content['name_table'] === 'feature' && !empty($tab_content['id_feature_value'])) { $sql = new DbQuery(); $sql->select('fvl.value'); $sql->from('feature_value', 'f'); $sql->innerJoin('feature_value_lang', 'fvl', 'fvl.id_feature_value = f.id_feature_value AND fvl.id_lang = '.(int)$this->context->employee->id_lang); $sql->where('fvl.id_feature_value = '.(int)$tab_content['id_feature_value']); $feature_value = Db::getInstance()->getValue($sql); $tab_content['name_id_table'] .= ' ('.$feature_value.')'; } } } } $actions = array( 'editTabContent' => array( 'action_class' => 'AppPET', 'class' => 'has-action', 'icon' => 'pencil-square-o', 'title' => $this->l('Edit') ), 'deleteTabContent' => array( 'action_class' => 'AppPET', 'class' => 'has-action', 'icon' => 'trash-o', 'title' => $this->l('Remove') ) ); $headers = array( 'id_tab_content' => $this->l('ID'), 'name_tab' => $this->l('Tab'), 'table' => $this->l('Type'), 'name_id_table' => '' ); if ((int)$data['massive'] === 0) { $headers['name_product'] = $this->l('Product'); } $headers['actions'] = $this->l('Actions'); $pagination = array( 'total' => $total_items, 'current_page' => $page, 'items_per_page' => $items_per_page, 'total_pages' => ceil((int)$total_items / (int)$items_per_page), 'badge' => 'badge-content-tabs' ); return array( 'message_code' => $this->core->CODE_SUCCESS, 'content' => $tabs_content, 'table' => '', 'headers' => $headers, 'actions' => $actions, 'truncate' => array(), 'prefix_row' => 'field', 'masive' => array(), 'status' => array(), 'pagination' => $pagination ); } public function getSettingsOfTabsList() { $id_lang = (isset($this->context->employee->id_lang)) ? $this->context->employee->id_lang : null; $tabs = PETTabClass::getTabs(null, false, $id_lang); foreach ($tabs as &$tab) { $tab['id'] = $tab['id_tab']; if ($tab['type'] === 'contact') { $tab['type_tab'] = $this->l('Contact'); } elseif ($tab['type'] === 'content') { $tab['type_tab'] = $this->l('Content'); } else { $tab['type_tab'] = $this->l('Content by product combination'); } } $actions = array( 'editTab' => array( 'action_class' => 'AppPET', 'class' => 'has-action', 'icon' => 'pencil-square-o', 'title' => $this->l('Edit') ), 'deleteTab' => array( 'action_class' => 'AppPET', 'class' => 'has-action', 'icon' => 'trash-o', 'title' => $this->l('Remove') ) ); $headers = array( 'id_tab' => $this->l('ID'), 'name' => $this->l('Name'), 'type_tab' => $this->l('Tab type'), 'position' => $this->l('Position'), 'active' => $this->l('Active'), 'actions' => $this->l('Actions'), ); $status = array( 'active' => array( ) ); $sort = array( 'action' => 'updateTabsPosition', 'id' => 'id_tab_content' ); return array( 'message_code' => $this->core->CODE_SUCCESS, 'content' => $tabs, 'table' => 'table-form-list-tabs', 'headers' => $headers, 'actions' => $actions, 'truncate' => array(), 'prefix_row' => 'field', 'masive' => array(), 'status' => $status, 'color' => array(), 'sort' => $sort ); } private function getSettingsForm() { $options = array( 'enable_debug' => array( 'name' => 'enable_debug', 'prefix' => 'chk', 'label' => $this->l('Test mode'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['PET_ENABLE_DEBUG'], 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'depends' => array( 'ip_debug' => array( 'name' => 'ip_debug', 'prefix' => 'txt', 'label' => $this->l('Test IP'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_IP_DEBUG'], 'hidden_on' => false ) ) ), 'show_empty_tabs' => array( 'name' => 'show_empty_tabs', 'prefix' => 'chk', 'label' => $this->l('Show empty tabs'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['PET_SHOW_EMPTY_TABS'], 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO') ), 'hook' => array( 'name' => 'hook', 'prefix' => 'lst', 'label' => $this->l('Show on the hook'), 'type' => $this->globals->type_control->select, 'data' => array( array('value' => self::HOOK_PRODUCT_TAB, 'text' => $this->l('Native horizontal')), array('value' => self::HOOK_PRODUCT_FOOTER, 'text' => 'Product footer'), array('value' => self::HOOK_DISPLAY_REASSURANCE, 'text' => 'Product right column'), array('value' => self::HOOK_CUSTOM, 'text' => $this->l('Custom')), ), 'default_option' => $this->config_vars['PET_HOOK'], 'option_value' => 'value', 'option_text' => 'text', 'tooltip' => array( 'warning' => array( 'title' => $this->l('Info'), 'content' => $this->l('Choose hook where the module is to be displayed') ) ), 'depends' => array( 'style_tabs' => array( 'name' => 'style_tabs', 'prefix' => 'lst', 'label' => $this->l('Tabs design'), 'type' => $this->globals->type_control->select, 'data' => array( array('value' => 'accordion', 'text' => $this->l('Accordion')), array('value' => 'list_vertical', 'text' => $this->l('Vertical tabs')), array('value' => 'tab_horizontal', 'text' => $this->l('Horizontal tabs')) ), 'default_option' => $this->config_vars['PET_STYLE_TABS'], 'option_value' => 'value', 'option_text' => 'text', 'hidden_on' => array( self::HOOK_PRODUCT_FOOTER, self::HOOK_DISPLAY_REASSURANCE, self::HOOK_CUSTOM ), 'tooltip' => array( 'warning' => array( 'title' => $this->l('Info'), 'content' => $this->l('Order in which the tabs are displayed in the FrontOffice') ) ), ), 'order_tabs' => array( 'name' => 'order_tabs', 'prefix' => 'lst', 'label' => $this->l('Order of tabs'), 'type' => $this->globals->type_control->select, 'data' => array( array('value' => 'native_first', 'text' => $this->l('Native tabs first')), array('value' => 'extratabs_first', 'text' => $this->l('Extra tabs first')) ), 'default_option' => $this->config_vars['PET_ORDER_TABS'], 'option_value' => 'value', 'option_text' => 'text', 'hidden_on' => array(self::HOOK_PRODUCT_FOOTER, self::HOOK_DISPLAY_REASSURANCE), 'tooltip' => array( 'warning' => array( 'title' => $this->l('Info'), 'content' => $this->l('Order in which the tabs are displayed in the FrontOffice') ) ) ), ) ), 'ignore_selectors' => array( 'name' => 'ignore_selectors', 'prefix' => 'txt', 'label' => $this->l('Selectors modules ignore', $this->name_file), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_IGNORE_SELECTORS'], 'tooltip' => array( 'information' => array( 'title' => $this->l('Info'), 'content' => $this->l('Edit this field only if the developers indicated') ) ) ) ); $form = array( 'tab' => 'settings', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-settings', 'icon_class' => 'save' ) ), 'options' => $options ); return $form; } private function getDesignForm() { $options = array( 'bg_color_tabs' => array( 'name' => 'bg_color_tabs', 'prefix' => 'txt', 'label' => $this->l('Background color tabs', $this->name_file), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_BG_COLOR_TABS'], 'color' => true ), 'font_color_tabs' => array( 'name' => 'font_color_tabs', 'prefix' => 'txt', 'label' => $this->l('Font color tabs', $this->name_file), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_FONT_COLOR_TABS'], 'color' => true ), 'bg_color_slted_tabs' => array( 'name' => 'bg_color_slted_tabs', 'prefix' => 'txt', 'label' => $this->l('Background color of selected tabs', $this->name_file), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_BG_COLOR_SLTED_TABS'], 'color' => true, 'tooltip' => array( 'information' => array( 'content' => $this->l('Applies only to non-native horizontal tabs') ) ) ), 'font_color_slted_tabs' => array( 'name' => 'font_color_slted_tabs', 'prefix' => 'txt', 'label' => $this->l('Font color of selected tabs', $this->name_file), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['PET_FONT_COLOR_SLTED_TABS'], 'color' => true, 'tooltip' => array( 'information' => array( 'content' => $this->l('Applies only to non-native horizontal tabs') ) ) ), ); $form = array( 'tab' => 'design', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-design', 'icon_class' => 'save' ) ), 'options' => $options ); return $form; } /*function backoffice*/ public function deleteUnrelatedContent() { //Eliminar contenido de tabs donde las id_tables o productos asociados ya no existan $content_tabs = PETTabContentClass::getIdTabs($this->context->employee->id_lang, null, array(), false); if (count($content_tabs) > 0) { foreach ($content_tabs as &$content) { $pet_tab_content = new PETTabContentClass($content['id_tab_content'], null, $content['id_shop']); $delete = true; if ((int)$content['id_product'] !== -1) { $product = new Product($content['id_product'], false, null, $content['id_shop']); if (!Validate::isLoadedObject($product)) { $delete = $pet_tab_content->delete(); } else { $table = ($content['name_table'] === 'category' ? 'category_product' : 'product'); $ids_tables = PETTabContentClass::getProductTable( $content['id_product'], $table, 'id_'.$content['name_table'] ); if (!in_array($content['id_table'], $ids_tables)) { if ($content['name_table'] === 'category') { $pet_tab_content->id_table = $product->id_category_default; $pet_tab_content->update(); } else { $delete = $pet_tab_content->delete(); } } } } else { if ((int)$content['massive'] === 1) { $id_tables = explode(',', $content['id_table']); foreach ($id_tables as $key => $id_table) { $isset = true; if ($content['name_table'] === 'category') { $isset = Category::categoryExists($id_table); } elseif ($content['name_table'] === 'supplier') { $isset = Supplier::supplierExists($id_table); } else { $isset = Manufacturer::manufacturerExists($id_table); } if (!$isset) { unset($id_tables[$key]); } } if (count($id_tables) === 0) { $delete = $pet_tab_content->delete(); } else { $pet_tab_content->update(); $content['id_table'] = implode(',', $id_tables); } } else { $isset = true; if ($content['name_table'] === 'category') { $isset = Category::categoryExists($content['id_table']); } elseif ($content['name_table'] === 'supplier') { $isset = Supplier::supplierExists($content['id_table']); } else { $isset = Manufacturer::manufacturerExists($content['id_table']); } if (!$isset) { $delete = $pet_tab_content->delete(); } } } if (!$delete) { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('There was an error deleting the content') ); } } } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('Content unrelated successfully removed') ); } public function getType() { $id_tab = Tools::getValue('id_tab'); $pet_tab_class = new PETTabClass((int)$id_tab); if (Validate::isLoadedObject($pet_tab_class)) { return array('message_code' => $this->core->CODE_SUCCESS, 'type' => $pet_tab_class->type); } return array('message_code' => $this->core->CODE_ERROR, 'message' => $this->l('Tab not exists')); } public function editTab() { $id_tab = Tools::getValue('id_tab', null); $id_shop = Tools::getValue('id_shop'); $pet_tab_class = new PETTabClass((int)$id_tab, null, $id_shop); if (Validate::isLoadedObject($pet_tab_class)) { return array('message_code' => $this->core->CODE_SUCCESS, 'pet_tab_class' => $pet_tab_class); } return array('message_code' => $this->core->CODE_ERROR, 'message' => $this->l('Tab not exists')); } public function updateTab() { $id_tab = Tools::getValue('id_tab', null); $names = Tools::getValue('names', array()); $active = Tools::getValue('active', false); $type = Tools::getValue('type', null); $name = array(); $default_language = (int)Configuration::get('PS_LANG_DEFAULT'); foreach ($names as $_name) { $name[$_name['id_lang']] = $_name['name']; if ($_name['id_lang'] == $default_language && Tools::isEmpty($name[$_name['id_lang']])) { $language = Language::getLanguage($_name['id_lang']); return array( 'message_code' => $this->core->CODE_ERROR, 'message' => sprintf($this->l('You must write the tab name at least in %s'), $language['name']) ); } } $query = new DbQuery(); $query->select('position'); $query->from('pet_tab_shop'); $query->where('id_shop = '.$this->context->shop->id); $query->orderBy('CAST(position AS unsigned) DESC'); $position = Db::getInstance()->getValue($query); $pet_tab_class = new PETTabClass($id_tab); $pet_tab_class->name = $name; $pet_tab_class->type = $type; $pet_tab_class->active = $active; if (Tools::isEmpty($id_tab)) { $pet_tab_class->position = (int) $position + 1; } if ($pet_tab_class->save()) { if (empty($id_tab)) { $pet_tab_class->update(); } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The tab was successfully saved') ); } return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying to save') ); } public function deleteTab() { $id_tab = Tools::getValue('id_tab', null); if (!Tools::isEmpty($id_tab)) { $pet_tab_class = new PETTabClass($id_tab); if (Validate::isLoadedObject($pet_tab_class) && $pet_tab_class->delete()) { $sql = new DbQuery(); $sql->select('id_tab_content'); $sql->from('pet_tab_content'); $sql->where('id_tab = '.(int)$id_tab); $tabs_content = Db::getInstance()->executeS($sql); if (is_array($tabs_content) && count($tabs_content) > 0) { foreach ($tabs_content as $tab_content) { $pet_tab_content = new PETTabContentClass($tab_content['id_tab_content']); $pet_tab_content->delete(); } } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The tab was successfully deleted.') ); } } return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying to delete.') ); } public function getListTab() { $id_lang = (isset($this->context->employee->id_lang)) ? $this->context->employee->id_lang : null; return PETTabClass::getTabs(null, true, $id_lang); } public function getFeatureValues() { $id_feature = Tools::getValue('id_feature'); $feature_values = FeatureValue::getFeatureValuesWithLang($this->context->employee->id_lang, $id_feature); return array('message_code' => $this->core->CODE_SUCCESS, 'data' => $feature_values); } public function getProductsByType() { $data = (object) Tools::getValue('data'); $id_table = $data->id_table; $table = $data->table; $products = array(); if ((int)$id_table === -1) { return $products; } $id_lang = (int)$this->context->employee->id_lang; if (empty($id_lang)) { $id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); } if ($table === 'manufacturer') { $manufacturer = new Manufacturer($id_table); $products = $manufacturer->getProductsLite($id_lang); } elseif ($table === 'supplier') { $supplier = new Supplier($id_table); $products = $supplier->getProductsLite($id_lang); } elseif ($table === 'category') { $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', $id_table, false); } elseif ($table === 'feature') { $sql = new DbQuery(); $sql->select('fp.id_product, pl.name'); $sql->from('feature_product', 'fp'); $sql->innerJoin('product', 'p', 'fp.id_product = p.id_product'); $sql->leftJoin('product_lang', 'pl', 'pl.id_product = p.id_product AND pl.id_lang = '.(int)$id_lang); $sql->where('p.active = 1 and fp.id_feature_value ='.(int) $id_table); $products = Db::getInstance()->executeS($sql); } return $products; } public function updateTabsPosition() { $items = Tools::getValue('items'); foreach ($items as $item) { $pet_tab_class = new PETTabClass((int)$item['id_item']); $pet_tab_class->position = (int)$item['index'] + 1; if (!$pet_tab_class->save()) { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying update the positions.') ); } } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('Positions updated successful') ); } public function updateTabContent($params = array()) { $params = Tools::getValue('params', $params); if ($params['type'] === self::COMBINATION) { $unchecked = empty($params['unchecked']) ? array() : $params['unchecked']; if (is_array($unchecked) && count($unchecked) > 0) { foreach ($unchecked as $id_combination) { $ids_tab_content = PETTabContentClass::getIdsTabContentByCombination( $params['id_tab'], $params['id_product'], $id_combination, false ); if (is_array($ids_tab_content) && count($ids_tab_content) > 0) { foreach ($ids_tab_content as $id_tab_content_) { $instance = new PETTabContentClass($id_tab_content_['id_tab_content']); $instance->delete(); } } } } $checked = $params['checked']; if (is_array($checked) && !empty($checked)) { foreach ($checked as $combination) { $content_combination = PETTabContentClass::getByCombination( $params['id_tab'], $params['table'], $params['id_table'], $params['id_product'], $combination['id_combination'] ); if (!is_array($combination['content'])) { $combination['content'] = Tools::jsonDecode($combination['content']); } $arr_content = array(); foreach ($combination['content'] as $content) { $content_tmp = $content->content; if (!Tools::getIsset('action')) { $content_tmp = self::htmlEncode($content_tmp, ENT_QUOTES, 'UTF-8'); } $arr_content[$content->id_lang] = $content_tmp; } $content_combination->content = $arr_content; $content_combination->id_feature_value = $params['id_feature_value']; $content_combination->customer_group_show = $params['customer_group_show']; if (!$content_combination->save()) { if (empty($params['id_tab_content'])) { $content_combination->update(); } return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying to save.') ); } } } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The tab content was successfully saved.') ); } else { $content_tab = $params['content']; //verifica que no exista ya las mismas condiciones del tab if (is_array($params['id_table'])) { foreach ($params['id_table'] as $key => $id) { $tab_content_exist = PETTabContentClass::tabContentExist( $params['id_tab'], true, null, $params['table'], $id ); if (empty($params['id_tab_content']) && !empty($tab_content_exist)) { unset($params['id_table'][$key]); } } if (count($params['id_table']) === 0) { $table_name = $this->l('categories'); if ($params['table'] === 'manufacturer') { $table_name = $this->l('manufacturers'); } elseif ($params['table'] === 'suppliers') { $table_name = $this->l('suppliers'); } return array( 'message' => $this->core->CODE_ERROR, 'message' => sprintf( $this->l('There is already content created for these %s in this tab.'), $table_name ) ); } } elseif ($params['id_product'] !== -1 && empty($params['id_tab_content'])) { $tab_content_exist = PETTabContentClass::tabContentExist( $params['id_tab'], false, $params['id_product'], $params['table'], $params['id_table'] ); if (!empty($tab_content_exist)) { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('The tab and product, already created, if you want to change it please look in the list and edit it.') ); } } if (!is_array($content_tab)) { $content_tab = Tools::jsonDecode($content_tab); } $arr_content = array(); foreach ($content_tab as $content) { $content_tmp = $content->content; if (!Tools::getIsset('action')) { $content_tmp = self::htmlEncode($content_tmp, ENT_QUOTES, 'UTF-8'); } $arr_content[$content->id_lang] = $content_tmp; } $id_table = $params['id_table']; if (is_array($id_table) && count($id_table) > 0) { $id_table = implode(',', $params['id_table']); } $pettab_content_class = new PETTabContentClass($params['id_tab_content']); $pettab_content_class->id_tab = $params['id_tab']; $pettab_content_class->id_product = $params['id_product']; $pettab_content_class->excluded_products = isset($params['excluded_products']) ? $params['excluded_products'] : ''; $pettab_content_class->name_table = $params['table']; $pettab_content_class->id_table = $id_table; $pettab_content_class->id_feature_value = $params['id_feature_value']; $pettab_content_class->customer_group_show = $params['customer_group_show']; $pettab_content_class->id_combination = PETTabContentClass::WITHOUT_COMBINATION; $pettab_content_class->content = $arr_content; $pettab_content_class->massive = is_array($params['id_table']) ? true : false; $result = $pettab_content_class->save(); if ($result) { if (empty($params['id_tab_content'])) { $pettab_content_class->update(); } return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The tab content was successfully saved.'), 'tab_content' => array( 'id_tab_content' => $pettab_content_class->id, 'id_tab' => $pettab_content_class->id_tab ) ); } else { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying to save.') ); } } } public function editTabContent() { $id_tab_content = Tools::getValue('id_tab_content', null); $id_shop = Tools::getValue('id_shop'); if (!Tools::isEmpty($id_tab_content)) { $pet_tab_content_class = new PETTabContentClass($id_tab_content, null, $id_shop); if (Validate::isLoadedObject($pet_tab_content_class)) { return $pet_tab_content_class; } } return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying get tab content.') ); } public function deleteTabContent($id_tab_content = null) { $id_tab_content = (!is_null($id_tab_content)) ? $id_tab_content : Tools::getValue('id_tab_content', null); if (!Tools::isEmpty($id_tab_content)) { $pet_tab_content_class = new PETTabContentClass($id_tab_content); if (Validate::isLoadedObject($pet_tab_content_class) && $pet_tab_content_class->delete()) { return array( 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The tab content was successfully deleted.') ); } } return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying to delete.') ); } public function findCombinations() { $id_lang = (isset($this->context->language->id)) ? $this->context->language->id : null; if (!Tools::isSubmit('id_product') || Tools::isEmpty('id_product')) { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while trying get combinations.') ); } $id_tab = Tools::getValue('id_tab'); $id_product = Tools::getValue('id_product'); $product = new Product($id_product); $color_by_default = '#BDE5F8'; if (version_compare(_PS_VERSION_, '1.5') >= 0) { $combinations = $product->getAttributeCombinations($id_lang); } else { $combinations = $product->getAttributeCombinaisons($id_lang); } $groups = array(); $comb_array = array(); if (is_array($combinations)) { foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['attributes'][] = array( $combination['group_name'], $combination['attribute_name'], $combination['id_attribute'] ); $comb_array[$combination['id_product_attribute']]['default_on'] = $combination['default_on']; if ($combination['is_color_group']) { $groups[$combination['id_attribute_group']] = $combination['group_name']; } } } if (isset($comb_array)) { foreach ($comb_array as $id_product_attribute => $product_attribute) { $list = ''; /* In order to keep the same attributes order */ asort($product_attribute['attributes']); foreach ($product_attribute['attributes'] as $attribute) { $list .= $attribute[0].' - '.$attribute[1].', '; } $list = rtrim($list, ', '); $comb_array[$id_product_attribute]['attributes'] = $list; if ($product_attribute['default_on']) { $comb_array[$id_product_attribute]['name'] = 'is_default'; $comb_array[$id_product_attribute]['color'] = $color_by_default; } $comb_array[$id_product_attribute]['content'] = PETTabContentClass::getContentCombination( $id_product, $id_product_attribute, $id_tab ); } $comb_array[0] = array( 'id_product_attribute' => 0, 'attributes' => $this->l('General (This will be shown if a combination is not added)'), 'content' => PETTabContentClass::getContentCombination( $id_product, PETTabContentClass::GENERAL_COMBINATION, $id_tab ) ); } return array('message_code' => $this->core->CODE_SUCCESS, 'combinations' => $comb_array); } public function getContentByCombination() { $id_product = Tools::getValue('id_product', 0); $id_attributes = Tools::getValue('id_attributes'); $id_combination = Product::getIdProductAttributesByIdAttributes($id_product, $id_attributes); $content = PETTabContentClass::getContentCombination( $id_product, $id_combination, null, (int)$this->context->language->id, true ); if (!empty($content)) { foreach ($content as $i => $_content) { $content[$i]['content'] = $_content['content']; } } return array('message_code' => $this->core->CODE_SUCCESS, 'content' => $content); } public static function htmlEncode($string) { return htmlentities($string, ENT_QUOTES, 'UTF-8'); } public static function htmlDecode($string) { return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); } public static function recurseCategory( &$array_categories, $categories, $current, $with_li = true, $id_category = 1, $id_selected = -1, $id_lang = 1, $id_shop = 1 ) { if ($id_category != 1) { if ($current != null) { if ($with_li) { $option = array( 'id_category' => $id_category, 'category' => str_repeat( ' ', $current['infos']['level_depth'] * 5 ).Tools::stripslashes($current['infos']['name']) ); } else { $category = new Category($current['infos']['id_parent'], $id_lang, $id_shop); $option = array( 'id_category' => $id_category, 'category' => $category->name.' > '.Tools::stripslashes($current['infos']['name']) ); } if ($id_selected == $id_category) { $option['selected'] = 'selected'; } array_push($array_categories, $option); } } if (isset($categories[$id_category])) { foreach (array_keys($categories[$id_category]) as $key) { self::recurseCategory( $array_categories, $categories, $categories[$id_category][$key], $with_li, $key, $id_selected, $id_lang, $id_shop ); } } } public function updateMasiveTabContent() { $tabs_save_content = Tools::getValue('tabs_save_content'); $response = array(); if (is_array($tabs_save_content) && count($tabs_save_content) > 0) { foreach ($tabs_save_content as &$tab_content) { if (!isset($tab_content['id_tab_content'])) { $tab_content['id_tab_content'] = null; } $data = $this->updateTabContent($tab_content); if ((int)$data['message_code'] === -1) { return array( 'message_code' => $this->core->CODE_ERROR, 'message' => $this->l('An error occurred while saving a content') ); } $data_tab_content = array(); if (isset($data['tab_content'])) { $data_tab_content = $data['tab_content']; } array_push($response, $data_tab_content); } } return array( 'response' => $response, 'message_code' => $this->core->CODE_SUCCESS, 'message' => $this->l('The content is created / updated correctly'), ); } public function masiveDeleteTabContent() { $tabs_delete_content = Tools::getValue('tabs_delete_content'); if (is_array($tabs_delete_content) && count($tabs_delete_content) > 0) { foreach ($tabs_delete_content as &$id_tab_content) { $this->deleteTabContent($id_tab_content); } } return array('message_code' => $this->core->CODE_SUCCESS); } /* ========= HOOKS BACKOFFICE========= */ public function hookActionAdminControllerSetMedia() { if ($this->context->controller->controller_name === 'AdminProducts') { $this->context->controller->addCSS($this->_path.'views/css/hook/admin_product_extra_tabs.css', 'all'); $this->context->controller->addCSS($this->_path.'views/css/lib/bootstrap/pts/pts-bootstrap.css', 'all'); $this->context->controller->addJS($this->_path.'views/js/lib/pts/tools.js'); $this->context->controller->addJS($this->_path.'views/js/lib/bootstrap/pts/bootstrap.min.js'); $this->context->controller->addJS($this->_path.'views/js/hook/admin_product_extra_tabs.js'); // $var_replace = $this->context->link->getBaseLink().basename(_PS_ADMIN_DIR_).'/'; $actions_controller_url = $this->context->link->getAdminLink('AdminActions'.$this->prefix_module); // $actions_controller_url = str_replace($var_replace, '', $actions_controller_url); $smarty_data = array( 'PresTeamShop' => array( 'pts_static_token' => Tools::encrypt($this->name.'/index'), 'module_dir' => $this->_path, 'success_code' => $this->core->CODE_SUCCESS, 'error_code' => $this->core->CODE_ERROR, 'actions_controller_url' => $actions_controller_url ) ); Media::addJsDef($smarty_data); } } public function hookActionProductUpdate($params) { $id_product = $params['id_product']; $id_category_default = $params['product']->id_category_default; if (!empty($id_product)) { $query = new DbQuery(); $query->select('*'); $query->from('pet_tab_content_shop'); $query->where('name_table = \'category\''); $query->where('id_table !=\'-1\''); $query->where('id_product = '.(int)$id_product); $query->groupBy('id_tab_content'); $results = Db::getInstance()->executeS($query); if ($results) { foreach ($results as $result) { $sql = new DbQuery(); $sql->select('id_product'); $sql->from('category_product'); $sql->where('id_product = '.(int)$id_product.' AND id_category = '.(int)$result['id_table']); $exist = Db::getInstance()->getValue($sql); if (!$exist) { Db::getInstance()->update( 'pet_tab_content_shop', array('id_table' => (int) $id_category_default), 'id_tab_content = '.(int)$result['id_tab_content'] ); } } } } return true; } public function hookDisplayAdminProductsExtra($params) { $tabs = PETTabClass::getTabs('content', true, $this->context->employee->id_lang); $tabs_lenght = count($tabs); $product = new Product($params['id_product']); $languages = Language::getLanguages(); for ($i = 0; $i < $tabs_lenght; $i++) { $tabs[$i]['own'] = false; $default_content_tab = array(); $content_tab = PETTabClass::getContentProductByIdTab( $tabs[$i]['id_tab'], $product->id, $tabs[$i]['id_shop'] ); if (is_array($content_tab) && count($content_tab) > 0) { $tabs[$i]['own'] = true; foreach ($content_tab as $content) { if (!isset($tabs[$i]['id_tab_content'])) { $tabs[$i]['id_tab_content'] = $content['id_tab_content']; } if (count($content) > 0) { $default_content_tab[$content['id_lang']] = $content['content']; } else { $default_content_tab[$content['id_lang']] = ''; } } } //add content to var $tabs[$i]['content'] = $default_content_tab; } $smarty_data = array( 'id_product' => $product->id, 'id_category' => $product->id_category_default, 'tabs' => $tabs, 'languages' => $languages, 'default_lenguage' => (int)Configuration::get('PS_LANG_DEFAULT') ); $this->smarty->assign($smarty_data); return $this->display(__FILE__, 'views/templates/hook/admin_product_extra_tabs.tpl'); } /* ========= HOOKS FRONTOFFICE========= */ public function hookDisplayProductExtraContent() { if (!$this->core->checkModulePTS() || !$this->core->isVisible() || $this->pet_hook_position !== self::HOOK_PRODUCT_TAB ) { return array(); } $id_product = Tools::getValue('id_product'); $data = $this->getProductTabs($id_product); $contents = array(); if ($data) { foreach ($data as $tab) { $class_tab = 'pet_native_horizontal'; if ($tab['type'] === 'combination') { $class_tab .= ' tab_combination_'.$tab['id_tab']; } $product_extra_content = new PrestaShop\PrestaShop\Core\Product\ProductExtraContent(); $product_extra_content->setTitle($tab['name_tab']); $product_extra_content->setContent($tab['content']); $product_extra_content->setAttr(array('class' => $class_tab)); array_push($contents, $product_extra_content); } } return $contents; } public function hookDisplayReassurance() { if (!Tools::isSubmit('id_product')) { return false; } return $this->hookProductContent(self::HOOK_DISPLAY_REASSURANCE); } public function hookDisplayFooterProduct() { return $this->hookProductContent(self::HOOK_PRODUCT_FOOTER); } public function hookProductExtraTabs() { return $this->hookProductContent(self::HOOK_CUSTOM); } public function hookProductContent($hook = '') { if (!$this->core->checkModulePTS() || !$this->core->isVisible() || $this->pet_hook_position !== $hook) { return; } $this->smarty->assign(array( 'CONFIGS' => $this->config_vars, 'theme_name' => _THEME_NAME_ )); return $this->display(__FILE__, 'views/templates/hook/product-extra-tabs.tpl'); } public function getProductTabs($id_product) { $content_tabs = array(); $aux_tab = array(); $tabs_content = PETTabContentClass::getContentTab( $this->context->language->id, array( 'id_product' => $id_product, 'all_products' => true, 'id_customer' => (int) $this->context->customer->id, 'active' => true ), null, null, 'CAST(ts.position AS unsigned) ASC ' ); if (!empty($tabs_content)) { foreach ($tabs_content as $key => $result) { //Validar si el producto pertenece a la tabla (categoría, proveedor, fabricante). $name_table = $result['name_table']; if ((int)$result['id_table'] !== -1) { if ($result['name_table'] === 'category') { $table = 'category_product'; } elseif ($result['name_table'] === 'feature') { $table = 'feature_product'; if (!empty($result['id_feature_value'])) { $name_table = 'feature_value'; } } else { $table = 'product'; } $ids_tables = PETTabContentClass::getProductTable($id_product, $table, 'id_'.$name_table); if ($result['massive']) { $id_table = explode(',', $result['id_table']); $intersect = array_intersect($ids_tables, $id_table); if (count($intersect) === 0) { unset($tabs_content[$key]); continue; } } else { if ($result['name_table'] === 'feature' && !empty($result['id_feature_value'])) { if (!in_array($result['id_feature_value'], $ids_tables)) { unset($tabs_content[$key]); continue; } } else { if (!in_array($result['id_table'], $ids_tables)) { unset($tabs_content[$key]); continue; } } } } // valida que el producto no esté en productos excluídos if (!$result['massive'] && !empty($result['excluded_products'])) { $excluded_products = explode(',', $result['excluded_products']); if (in_array($id_product, $excluded_products)) { unset($tabs_content[$key]); continue; } } if ($result['type'] === self::CONTACT) { $email_customer = ''; if (isset($this->cookie) && isset($this->cookie->email) && Validate::isEmail($this->cookie->email) ) { $email_customer = $this->cookie->email; } $email = Tools::safeOutput(Tools::getValue('from', $email_customer)); $this->smarty->assign(array( 'contact' => array( 'email' => $email ) )); $result['content'] = $this->display(__FILE__, 'views/templates/hook/contact-form.tpl'); } else { $result['content'] = self::htmlDecode($result['content']); } if (!$this->config_vars['PET_SHOW_EMPTY_TABS'] && empty($result['content'])) { continue; } if (in_array($result['id_tab'], $aux_tab)) { $key = array_search($result['id_tab'], $aux_tab); $content_tabs[$key]['content'] .= $result['content']; } else { $content_tabs[$result['id_tab_content']] = $result; } $aux_tab[$result['id_tab_content']] = $result['id_tab']; } return array_values($content_tabs); } return array(); } public function hookHeader() { if (!$this->core->isVisible()) { return false; } if (Tools::getIsset('controller') && Tools::getValue('controller') == 'product') { $this->context->controller->addCSS(($this->_path).'views/css/lib/font-awesome/font-awesome.css', 'all'); $this->context->controller->addCSS(($this->_path).'views/css/lib/bootstrap/pts/pts-bootstrap.css', 'all'); $this->context->controller->addCSS(($this->_path).'views/css/front/productextratabs.css', 'all'); $this->context->controller->addCSS(($this->_path).'views/css/front/override.css', 'all'); $this->context->controller->addJS(($this->_path).'views/js/hook/hook-product-footer.js'); $this->context->controller->addJS(($this->_path).'views/js/front/override.js'); $this->context->controller->addJS(($this->_path).'views/js/lib/pts/tools.js'); $smarty_data = array( 'CONFIGS' => $this->config_vars, 'theme_name' => _THEME_NAME_, 'PresTeamShop' => array( 'actions_productextratabs' => $this->context->link->getModuleLink($this->name, 'actions'), 'module_dir' => $this->_path, 'pts_static_token' => Tools::encrypt($this->name.'/index'), 'success_code' => $this->core->CODE_SUCCESS, 'error_code' => $this->core->CODE_ERROR, ) ); if ($this->config_vars['PET_HOOK'] !== 'hook_display_product_extra_content') { $id_product = Tools::getValue('id_product'); $tabs = $this->getProductTabs($id_product); $smarty_data['PresTeamShop']['tabs'] = $tabs; $smarty_data['id_product'] = $id_product; } $this->context->smarty->assign($smarty_data); $smarty_data['Msg'] = array( 'reviews_tab' => $this->l('Reviews') ); Media::addJsDef($smarty_data); return $this->display(__FILE__, 'views/templates/hook/theme.tpl'); } } }