ach34 Posted November 2, 2016 Share Posted November 2, 2016 Bonjour, Je veux faire un hook dans editorial.tpl mais je n'y arrive pas. Voici mon code : Dans "themes\Ps_montheme\modules\editorial\" j'ai mis mes 2 fichiers editorial.tpl et editorial.php editorial.php : public function install() { if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader') || !$this->registerHook('displayhomeimg')) return false; ......... et public function hookdisplayhomeimg($params) { return '<div>toto toto toto toto</div>'; } Dans editorial.tpl <div id="editorial_block_center" class="editorial_block"> {hook h='displayhomeimg'} <div>-- {$h} --</div> {if $editorial->body_home_logo_link}<a href="{$editorial->body_home_logo_link|escape:'html':'UTF-8'}" title="{$editorial->body_title|escape:'html':'UTF-8'|stripslashes}">{/if} {if $homepage_logo}<img class="img-responsive" src="{$link->getMediaLink($image_path)|escape:'html'}" alt="{$editorial->body_title|escape:'html':'UTF-8'|stripslashes}" {if $image_width}width="{$image_width}"{/if} {if $image_height}height="{$image_height}" {/if}/>{/if} {if $editorial->body_home_logo_link}</a>{/if} {if $editorial->body_logo_subheading}<p id="editorial_image_legend">{$editorial->body_logo_subheading|stripslashes}</p>{/if} {if $editorial->body_title}<h1>{$editorial->body_title|stripslashes}</h1>{/if} {if $editorial->body_subheading}<h2>{$editorial->body_subheading|stripslashes}</h2>{/if} {if $editorial->body_paragraph}<div class="rte">{$editorial->body_paragraph|stripslashes}</div>{/if} </div> ça marche. Je dois faire un truc de pas bon. Merci pour votre aide Link to comment Share on other sites More sharing options...
Martin Uker K Posted November 2, 2016 Share Posted November 2, 2016 Okay, Ton problème est avec ta méthode d'override. tu ne peux pas override editorial.php dans ton thème (.tpl c'est okay). Ton fichier editorial.php n'est donc pas au bon endroit. Il devrait être dans "override/module/editorial/editorial.php" Peux-tu me montrer ton fichier au complet, il faut aussi changer le nom de la classe et assurer qu'elle hérite bien de la classe native du module. De plus, il faut que tu surcharge (overridE) seulement les méthodes que tu as besoin. Martin. Link to comment Share on other sites More sharing options...
ach34 Posted November 2, 2016 Author Share Posted November 2, 2016 Oui voici mon fichier editorial.php : <?php /* * 2007-2015 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 [email protected] 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 <[email protected]> * @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; class Editorial extends Module { public function __construct() { $this->name = 'editorial'; $this->tab = 'front_office_features'; $this->version = '2.6.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Home text editor'); $this->description = $this->l('A text-edit module for your homepage.'); $path = dirname(__FILE__); if (strpos(__FILE__, 'Module.php') !== false) $path .= '/../modules/'.$this->name; include_once $path.'/EditorialClass.php'; } public function install() { if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader') || !$this->registerHook('displayhomeimg')) return false; $res = Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'editorial` ( `id_editorial` int(10) unsigned NOT NULL auto_increment, `id_shop` int(10) unsigned NOT NULL , `body_home_logo_link` varchar(255) NOT NULL, PRIMARY KEY (`id_editorial`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8' ); if ($res) $res &= Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'editorial_lang` ( `id_editorial` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `body_title` varchar(255) NOT NULL, `body_subheading` varchar(255) NOT NULL, `body_paragraph` text NOT NULL, `body_logo_subheading` varchar(255) NOT NULL, PRIMARY KEY (`id_editorial`, `id_lang`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8' ); if ($res) foreach (Shop::getShops(false) as $shop) $res &= $this->createExampleEditorial($shop['id_shop']); if (!$res) $res &= $this->uninstall(); return (bool)$res; } private function createExampleEditorial($id_shop) { $editorial = new EditorialClass(); $editorial->id_shop = (int)$id_shop; $editorial->body_home_logo_link = 'http://www.prestashop.com'; foreach (Language::getLanguages(false) as $lang) { $editorial->body_title[$lang['id_lang']] = 'Lorem ipsum dolor sit amet'; $editorial->body_subheading[$lang['id_lang']] = 'Excepteur sint occaecat cupidatat non proident'; $editorial->body_paragraph[$lang['id_lang']] = '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>'; $editorial->body_logo_subheading[$lang['id_lang']] = 'Lorem ipsum presta shop amet'; } return $editorial->add(); } public function uninstall() { $res = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'editorial`'); $res &= Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'editorial_lang`'); if ($res == 0 || !parent::uninstall()) return false; return true; } private function initForm() { $languages = Language::getLanguages(false); foreach ($languages as $k => $language) $languages[$k]['is_default'] = (int)$language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'); $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'editorial'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->languages = $languages; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = true; $helper->toolbar_scroll = true; $helper->toolbar_btn = $this->initToolbar(); $helper->title = $this->displayName; $helper->submit_action = 'submitUpdateEditorial'; $file = dirname(__FILE__).'/img/homepage_logo_'.(int)$this->context->shop->id.'.jpg'; $logo = (file_exists($file) ? '<img src="'.$this->_path.'img/homepage_logo_'.(int)$this->context->shop->id.'.jpg">' : ''); $this->fields_form[0]['form'] = array( 'tinymce' => true, 'legend' => array( 'title' => $this->displayName, 'image' => $this->_path.'logo.gif' ), 'submit' => array( 'name' => 'submitUpdateEditorial', 'title' => $this->l('Save '), 'class' => 'button pull-right' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Main title'), 'name' => 'body_title', 'lang' => true, 'size' => 64, 'desc' => $this->l('Appears along top of your homepage'), ), array( 'type' => 'text', 'label' => $this->l('Subheading'), 'name' => 'body_subheading', 'lang' => true, 'size' => 64, ), array( 'type' => 'textarea', 'label' => $this->l('Introductory text'), 'name' => 'body_paragraph', 'lang' => true, 'autoload_rte' => true, 'desc' => $this->l('For example... explain your mission, highlight a new product, or describe a recent event.'), 'cols' => 60, 'rows' => 30 ), array( 'type' => 'file', 'label' => $this->l('Homepage logo'), 'name' => 'body_homepage_logo', 'display_image' => true, 'image' => $logo, 'delete_url' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteLogoImage=1' ), array( 'type' => 'text', 'label' => $this->l('Homepage logo link'), 'name' => 'body_home_logo_link', 'size' => 33, ), array( 'type' => 'text', 'label' => $this->l('Homepage logo subheading'), 'name' => 'body_logo_subheading', 'lang' => true, 'size' => 33, ), ) ); return $helper; } private function initToolbar() { $this->toolbar_btn['save'] = array( 'href' => '#', 'desc' => $this->l('Save') ); return $this->toolbar_btn; } public function getContent() { $this->_html = ''; $this->postProcess(); $helper = $this->initForm(); $id_shop = (int)$this->context->shop->id; $editorial = EditorialClass::getByIdShop($id_shop); if (!$editorial) //if editorial ddo not exist for this shop => create a new example one $this->createExampleEditorial($id_shop); foreach ($this->fields_form[0]['form']['input'] as $input) //fill all form fields { if ($input['name'] != 'body_homepage_logo') $helper->fields_value[$input['name']] = $editorial->{$input['name']}; } $file = dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg'; $helper->fields_value['body_homepage_logo']['image'] = (file_exists($file) ? '<img src="'.$this->_path.'img/homepage_logo_'.(int)$id_shop.'.jpg" />' : ''); if ($helper->fields_value['body_homepage_logo'] && file_exists($file)) $helper->fields_value['body_homepage_logo']['size'] = filesize($file) / 1000; $this->_html .= $helper->generateForm($this->fields_form); return $this->_html; } public function postProcess() { $errors = ''; $id_shop = (int)$this->context->shop->id; // Delete logo image retrocompat 1.5 if (Tools::isSubmit('deleteLogoImage') || Tools::isSubmit('deleteImage')) { if (!file_exists(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg')) $errors .= $this->displayError($this->l('This action cannot be made.')); else { unlink(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 1); $this->_clearCache('editorial.tpl'); Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)Tab::getIdFromClassName('AdminModules').(int)$this->context->employee->id)); } $this->_html .= $errors; } if (Tools::isSubmit('submitUpdateEditorial')) { $id_shop = (int)$this->context->shop->id; $editorial = EditorialClass::getByIdShop($id_shop); $editorial->copyFromPost(); if (empty($editorial->id_shop)) $editorial->id_shop = (int)$id_shop; $editorial->save(); /* upload the image */ if (isset($_FILES['body_homepage_logo']) && isset($_FILES['body_homepage_logo']['tmp_name']) && !empty($_FILES['body_homepage_logo']['tmp_name'])) { Configuration::set('PS_IMAGE_GENERATION_METHOD', 1); if (file_exists(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg')) unlink(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg'); if ($error = ImageManager::validateUpload($_FILES['body_homepage_logo'])) $errors .= $error; elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmp_name)) return false; elseif (!ImageManager::resize($tmp_name, dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg')) $errors .= $this->displayError($this->l('An error occurred while attempting to upload the image.')); if (isset($tmp_name)) unlink($tmp_name); } $this->_html .= $errors == '' ? $this->displayConfirmation($this->l('Settings updated successfully.')) : $errors; if (file_exists(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg')) { list($width, $height, $type, $attr) = getimagesize(dirname(__FILE__).'/img/homepage_logo_'.(int)$id_shop.'.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_WIDTH', (int)round($width)); Configuration::updateValue('EDITORIAL_IMAGE_HEIGHT', (int)round($height)); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 0); } $this->_clearCache('editorial.tpl'); Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)Tab::getIdFromClassName('AdminModules').(int)$this->context->employee->id)); } return true; } // notre fonction qui va afficher le contenu de notre hook public function hookdisplayhomeimg($params) { return '<div>toto toto toto toto</div>'; } public function hookDisplayHome($params) { if (!$this->isCached('editorial.tpl', $this->getCacheId())) { $id_shop = (int)$this->context->shop->id; $editorial = EditorialClass::getByIdShop($id_shop); if (!$editorial) return; $editorial = new EditorialClass((int)$editorial->id, $this->context->language->id); if (!$editorial) return; $this->smarty->assign( array( 'editorial' => $editorial, 'default_lang' => (int)$this->context->language->id, 'image_width' => Configuration::get('EDITORIAL_IMAGE_WIDTH'), 'image_height' => Configuration::get('EDITORIAL_IMAGE_HEIGHT'), 'id_lang' => $this->context->language->id, 'homepage_logo' => !Configuration::get('EDITORIAL_IMAGE_DISABLE') && file_exists('modules/editorial/img/homepage_logo_'.(int)$id_shop.'.jpg'), 'image_path' => $this->_path.'img/homepage_logo_'.(int)$id_shop.'.jpg' ) ); } return $this->display(__FILE__, 'editorial.tpl', $this->getCacheId()); } public function hookdisplayTopColumn($params) { if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'index') return; return $this->hookDisplayHome($params); } public function hookDisplayHeader() { if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'index') return; $this->context->controller->addCSS(($this->_path).'css/editorial.css', 'all'); } } Link to comment Share on other sites More sharing options...
ach34 Posted November 2, 2016 Author Share Posted November 2, 2016 (edited) J'ai copié le fichier editorial.php modifié dans "override/module/editorial/"... page blanche J'ai copié le fichier editorial.php originale dans "override/module/editorial/"... page blanche Merci de votre aide ???? Edited November 2, 2016 by ach34 (see edit history) Link to comment Share on other sites More sharing options...
Martin Uker K Posted November 2, 2016 Share Posted November 2, 2016 Désolé du temps...j'ai un travail de migration à faire en même temps : Editorial extends Module Devrait être EditorialOverride extends Editorial De plus, votre classe de modification surcharge effectivement TOUTES les fonctions, ne mettez que ceux que vous voulez...Install et votre nouvelle fonction. Cordialement, Martin. Link to comment Share on other sites More sharing options...
ach34 Posted November 2, 2016 Author Share Posted November 2, 2016 (edited) J'ai suivi votre explication, je n'ai plus de page blanche mais il n'affiche pas mon résultat. if (!defined('_PS_VERSION_')) exit; class EditorialOverride extends Editorial { public function install() { return parent::install() && $this->registerHook('displayHomeImg'); } // notre fonction qui va afficher le contenu de notre hook public function hookDisplayHomeImg() { return "toto"; } } Edited November 2, 2016 by ach34 (see edit history) Link to comment Share on other sites More sharing options...
Martin Uker K Posted November 2, 2016 Share Posted November 2, 2016 Avez-vous 1 : Réinstallé le module? (Votre register hook étant dans install, le hook n'existera pas avant que vous réinstalliez) 2 : Testé si le hook existe (Allez dans "Positions" sous module et essayez d'installer le module sur le hook) Martin. 1 Link to comment Share on other sites More sharing options...
ach34 Posted November 2, 2016 Author Share Posted November 2, 2016 C'est bon ça marche ! Merci pour l'aide Link to comment Share on other sites More sharing options...
Martin Uker K Posted November 2, 2016 Share Posted November 2, 2016 Toujours un plaisir! C'était un problème de réinstall? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now