Spaceshipone Posted November 8, 2016 Share Posted November 8, 2016 Bonjour, Je me lance dans la découverte de prestashop et la création de module et j'ai repris un tutoriel pour créer un module qui affiche un message sur la page d'accueil. J'aimerai maintenant faire apparaître ce message sur la page mon-compte (my-account.tpl) et c'est là que je coince. Comment faire pour que le message s'affiche sur une autre page ? Voici mon code : /** * monmodule.php * * Auteur: moi * Website: * Date: 03/11/2016 * Version: 0.1 */ if (!defined('_PS_VERSION_')) exit; class monmodule extends Module { public function __construct() { $this->name = 'monmodule'; $this->tab = 'front_office_features'; $this->version = '0.1'; $this->author = 'Moi'; $this->need_instance = 0; parent::__construct(); $this->context->controller->addCSS(($this->_path).'monmodule.css', 'all'); $this->displayName = $this->l('Affichage message accueil'); $this->description = $this->l('Affiche un message d\'accueil.'); } // :: Install : on enregistre le Hook "home" si il n'existe pas (peu probable, mais on ne sait jamais…) public function install() { if (!parent::install() OR !$this->registerHook('home')) return false; return true; } // :: Uninstall, no comment public function uninstall() { if (!parent::uninstall()) return false; return true; } // :: Hook Home : c'est là où sera affiché notre Bloc de texte (en Homepage) function hookHome($params) { // On assigne la variable "CHAMP_TINYMCE", utilisée dans le fichier TPL monmodule.tpl $this->context->smarty->assign(array('CHAMP_TINYMCE' => Configuration::get('CHAMP_TINYMCE'))); // On indique que le fichier TPL suivant sera le fichier de Template à afficher (il contient notre Bloc de texte) return $this->display(__FILE__, 'monmodule.tpl', $this->getCacheId()); } // :: Ici on indique le contenu de la page "Configuration" du plugin, et ses messages (erreur & succès) public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; // Si on envoie le formulaire "submitFormChamps"… if (Tools::isSubmit('submitFormChamps')) { // On récupère l'id des languages sur la variable $lang foreach (Language::getLanguages(false) as $lang) // On assigne CHAMP_TINYMCE à la value de text_X (X = numéro de votre langue, ici "1") Configuration::updateValue('CHAMP_TINYMCE', Tools::getValue('text_'.(int)$lang['id_lang']), true); // IMPORTANT: true = autoriser les balises HTML dans la BDD ! // Si il y a erreur… if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); // Sinon, success ! On affiche donc le message de confirmation d'enregistrement du texte dans la BDD else $output .= $this->displayConfirmation($this->l('Modifications enregistrées')); } // On affiche le formulaire avec le champ TinyMCE via $this->displayForm(); return $output.$this->displayForm(); } public function displayForm() { $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Champ TinyMCE'), ), 'input' => array( 'CHAMP_TINYMCE' => array( 'type' => 'hidden', 'name' => 'CHAMP_TINYMCE' ), 'content' => array( 'type' => 'textarea', 'label' => $this->l('Texte du Champ'), 'lang' => true, 'name' => 'text', 'cols' => 40, 'rows' => 10, 'class' => 'rte', 'autoload_rte' => true, ), ), 'submit' => array( 'title' => $this->l('Save'), ) ); $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'monmodule'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); foreach (Language::getLanguages(false) as $lang) $helper->languages[] = array( 'id_lang' => $lang['id_lang'], 'iso_code' => $lang['iso_code'], 'name' => $lang['name'], 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) ); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; $helper->toolbar_scroll = true; $helper->title = $this->displayName; $helper->submit_action = 'submitFormChamps'; $helper->fields_value = $this->getFormValues(); return $helper->generateForm(array(array('form' => $fields_form))); } public function getFormValues() { $fields_value = array(); // On charge le Texte sauvegardé dans la colonne "value" de la Table "ps_configuration" $CHAMP_TINYMCE = Configuration::get('CHAMP_TINYMCE'); foreach (Language::getLanguages(false) as $lang) // Si besoin d'utiliser la traduction $fields_value['text'][(int)$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang'], ''); // On load le contenu du textarea ("text_X", text_1 pour FR) qui servira à charger le contenu du champ TINYMCE $fields_value['text'][(int)$lang['id_lang']] = $CHAMP_TINYMCE; return $fields_value; } } Link to comment Share on other sites More sharing options...
Spaceshipone Posted November 9, 2016 Author Share Posted November 9, 2016 Personne ne peut m'aider ? Link to comment Share on other sites More sharing options...
PixGeek Posted November 12, 2016 Share Posted November 12, 2016 (edited) modifie : public function install() { if (!parent::install() OR !$this->registerHook('home')) return false; return true; } part : public function install() { if (!parent::install() OR !$this->registerHook('home') OR !$this->registerHook('account')) return false; return true; } le hook 'account' tu dois l'ajouter sur ton fichier tpl, a l'endroit que tu souhaites qu'il s'affiche Edited November 12, 2016 by prestajoie.ch (see edit history) 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