name = 'overridetemplate'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Aberit'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->bootstrap = true; $this->displayName = $this->l('Override template'); $this->description = $this->l('Override template'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get(self::MODULE_NAME)) { $this->warning = $this->l('Module is not configured.'); } parent::__construct(); } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } return parent::install() && $this->registerHook('displayOverrideTemplate') && $this->registerHook('displayFooterBefore') && $this->registerHook('displayWrapperTop'); } public function uninstall() { $this->unregisterHook('displayOverrideTemplate'); $this->unregisterHook('displayFooterBefore'); $this->unregisterHook('displayWrapperTop'); if (!parent::uninstall() || !Configuration::deleteByName(self::MODULE_NAME) ) { return false; } return true; } public function hookDisplayOverrideTemplate($params){ if ($params['template_file'] == 'contact') { $data = $this->getConfigFieldsValues(); $langId = $this->context->language->id; $this->context->smarty->assign('contactInfoLeft', $data['CONTACT_INFO_LEFT'][$langId]); $this->context->smarty->assign('contactInfoRight', $data['CONTACT_INFO_RIGHT'][$langId]); $this->context->smarty->assign('contactInfoDesc', $data['CONTACT_INFO_DESC'][$langId]); return 'module:'.$this->name.'/views/templates/hook/contact_page.tpl'; } } public function hookDisplayFooterBefore($params){ // if(isset($this->context->controller->php_self) // && (($this->context->controller->php_self == 'cms' && in_array(Tools::getValue('id_cms'), [8])) // || ($this->context->controller->php_self == 'cms' && in_array(Tools::getValue('id_cms'), [16])) // || ($this->context->controller->php_self == 'cms' && in_array(Tools::getValue('id_cms'), [17])) // || ($this->context->controller->php_self == 'cms' && in_array(Tools::getValue('id_cms'), [18])) // || ($this->context->controller->php_self == 'contact'))) { // $blog = new PhBlogRecentPosts(); // return $blog->hookDisplaySimpleBlogRecentPosts(['template' => 'recent']); // } } public function hookDisplayWrapperTop($params){ if($this->context->controller->php_self === 'cms' && in_array(Tools::getValue('id_cms'), [9])) { return $this->display(__FILE__, 'views/templates/hook/category_yours_baner.tpl'); } if($this->context->controller->php_self === 'category') { return $this->display(__FILE__, 'views/templates/hook/category_baner.tpl'); } if($this->context->controller->php_self === 'contact') { return $this->display(__FILE__, 'views/templates/hook/contact_baner.tpl'); } // TODO: added header to custom page template if($this->context->controller->php_self === 'cms' && in_array(Tools::getValue('id_cms'), [16])) { return $this->display(__FILE__, 'views/templates/hook/architekci_baner.tpl'); } if($this->context->controller->php_self === 'cms' && in_array(Tools::getValue('id_cms'), [17])) { return $this->display(__FILE__, 'views/templates/hook/dystrybutorzy_baner.tpl'); } if($this->context->controller->php_self === 'cms' && in_array(Tools::getValue('id_cms'), [18])) { return $this->display(__FILE__, 'views/templates/hook/struktury_baner.tpl'); } } public function getContent() { $output = ''; if (Tools::isSubmit('submitOverrideTemplate')) { $contactInfo = ['left' => [], 'right' => [], 'desc']; foreach ($_POST as $key => $value) { if (preg_match('/CONTACT_INFO_LEFT_/i', $key)) { $id_lang = preg_split('/CONTACT_INFO_LEFT_/i', $key); $contactInfo['left'][(int) $id_lang[1]] = $value; } if (preg_match('/CONTACT_INFO_RIGHT_/i', $key)) { $id_lang = preg_split('/CONTACT_INFO_RIGHT_/i', $key); $contactInfo['right'][(int) $id_lang[1]] = $value; } if (preg_match('/CONTACT_INFO_DESC_/i', $key)) { $id_lang = preg_split('/CONTACT_INFO_DESC_/i', $key); $contactInfo['desc'][(int) $id_lang[1]] = $value; } } Configuration::updateValue('CONTACT_INFO_LEFT', $contactInfo['left'], true); Configuration::updateValue('CONTACT_INFO_RIGHT', $contactInfo['right'], true); Configuration::updateValue('CONTACT_INFO_DESC', $contactInfo['desc'], true); $this->_clearCache('*'); $output .= $this->displayConfirmation($this->trans('The settings have been updated.', [], 'Admin.Notifications.Success')); } return $output . $this->renderForm(); } public function renderForm() { $fields_form = [ 'form' => [ 'legend' => [ 'title' => $this->trans('Settings', [], 'Admin.Global'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'textarea', 'lang' => true, 'autoload_rte' => true, 'label' => $this->trans( 'Informacje kontaktowe - opis:', [], 'Modules.OverrideTemplate.Admin' ), 'name' => 'CONTACT_INFO_DESC', ], [ 'type' => 'textarea', 'lang' => true, 'autoload_rte' => true, 'label' => $this->trans( 'Informacje kontaktowe - lewa kolumna:', [], 'Modules.OverrideTemplate.Admin' ), 'name' => 'CONTACT_INFO_LEFT', ], [ 'type' => 'textarea', 'lang' => true, 'autoload_rte' => true, 'label' => $this->trans( 'Informacje kontaktowe - prawa kolumna:', [], 'Modules.OverrideTemplate.Admin' ), 'name' => 'CONTACT_INFO_RIGHT', ], ], 'submit' => [ 'title' => $this->trans('Save', [], 'Admin.Actions'), ], ], ]; $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT')); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'submitOverrideTemplate'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; return $helper->generateForm([$fields_form]); } public function getConfigFieldsValues() { $return = []; $languages = Language::getLanguages(false); foreach ($languages as $lang) { $return['CONTACT_INFO_LEFT'][(int) $lang['id_lang']] = Tools::getValue( 'CONTACT_INFO_LEFT_' . (int) $lang['id_lang'], Configuration::get('CONTACT_INFO_LEFT', (int) $lang['id_lang']) ); $return['CONTACT_INFO_RIGHT'][(int) $lang['id_lang']] = Tools::getValue( 'CONTACT_INFO_RIGHT_' . (int) $lang['id_lang'], Configuration::get('CONTACT_INFO_RIGHT', (int) $lang['id_lang']) ); $return['CONTACT_INFO_DESC'][(int) $lang['id_lang']] = Tools::getValue( 'CONTACT_INFO_DESC_' . (int) $lang['id_lang'], Configuration::get('CONTACT_INFO_DESC', (int) $lang['id_lang']) ); } return $return; } }