vinoalvino Posted March 28, 2010 Share Posted March 28, 2010 Ammettiamo, come nel mio caso, di voler aggiungere e gestire un nuovo HOOK per una barra di navigazione nell'header subito dopo . Vediamo come fare.Nel modulo che stiamo realizzando serve:1) una funzione che aggiunge in tabella PS_HOOK il nuovo Hook /**********************/ /*** ADD A HOOK ***/ /**********************/ private function addMyHook( $HookName, $HookTitle, $HookDescription ) { if ( ! Db::getInstance()->getRow("SELECT `id_hook` FROM `"._DB_PREFIX_."hook` WHERE `name` = '$HookName' LIMIT 1") ) { Db::getInstance()->AutoExecute(_DB_PREFIX_.'hook', array('id_hook' => NULL, 'name' => $HookName, 'title' => $HookTitle, 'description' => $HookDescription, 'position' => '1'), 'INSERT'); } } 2) la chiamata a tale funzione nell'installazione del modulo PRIMA DI register! public function install() { /** CREATE HOOK **/ $this->addMyHook('navMenuBar', 'navigation bar hook', 'hook added by VV 28-3-2010' ); if (!parent::install() OR !$this->registerHook('navMenuBar')) return false; ...... 3) La gestione dell'evento Hook (basta chiamare la funzione hookNomeDelNuovoHook) function hooknavMenuBar($params) { global $smarty, $cookie, $cart; .... Dovremmo essere apposto per l'installazione. Vediamo come si disinstalla:4) Una funzione che elimina il nostro Hook e tutti gli agganci dei moduli (!) /**********************/ /*** DEL A HOOK ***/ /**********************/ private function delMyHook( $HookName ) { Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'hook_module` WHERE `id_hook` IN ( SELECT `id_hook` FROM `'._DB_PREFIX_."hook` WHERE `name` = '$HookName' )"); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_."hook` WHERE `name` = '$HookName' LIMIT 1") ; } 5) la chiamata a questa funzione in unistall() public function uninstall() { if (!parent::uninstall() ) return false; /** DROP HOOK **/ $this->delMyHook('navMenuBar'); Non abbiamo mica finito ... 6) Dobbiamo ora modificare il tpl e il php del 'pezzo' che vogliamo modificare; ammettiamo sia l'header quindi editiamo il file prestashop/themes/tuothema/header.tpl ed aggiungiamo il nostro hook 7) Ora editiamo il file prestashop/header.php $smarty->assign(array( 'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'), 'HOOK_TOP' => Module::hookExec('top'), 'HOOK_NAVMENUBAR'=> Module::hookExec('navMenuBar'), // riga aggiunta 'static_token' => Tools::getToken(false), 'token' => Tools::getToken(), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'content_only' => intval(Tools::getValue('content_only')) )); Bel casino aggiungere un hook ... ma spesso non possiamo farne a meno!Come avrete notato non gestisco gli eventuali errori delle funzioni aggiunte, cosa che inizialmente avevo implementato, perché se qualcosa va storto nel ciclo installa/disinstalla si creano pericolose situazioni di stallo (fidatevi) {$HOOK_NAVMENUBAR} Link to comment Share on other sites More sharing options...
Pr3z1oso Posted March 28, 2010 Share Posted March 28, 2010 grazie vinoalvino, sicuramente utile Link to comment Share on other sites More sharing options...
Iknusa Posted November 8, 2011 Share Posted November 8, 2011 io non ho capito come devo fare...me lo potresti rispiegare? 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