michael-marinetti

quick done new hook in a module

Feb 9th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. // quick done example for creating a new hook in PrestaShop 1.4.x
  3. // /!\ Not tested,
  4.  
  5. class Mymodule extends Module {
  6.     public function install(){
  7.         // let's create the hook (if it not exists)
  8.         $hook = new Hook();
  9.         $hook->name = 'top_menu';
  10.         $res = $hook->save();
  11.         // return true on install succeed
  12.         if ($res && parent::install())
  13.             return true;
  14.         return false;
  15.     }
  16.     public function uninstall()
  17.     {
  18.         // uninstall the module will uninstall the hook :)
  19.         $hook = Hook::get('top_menu');
  20.         $res = $hook->delete();
  21.         // return true on uninstall succeed
  22.         if ($res && parent::uninstall())
  23.             return true;
  24.         return false;
  25.     }
  26.     public function hookTop_Menu(){
  27.         // of course, your theme contains {$TOP_MENU} somewhere !
  28.        
  29.         // feel free to execute any code here
  30.         $a = 1;$b = 2; $c = $a + $b;
  31.        
  32.         global $smarty;
  33.         // (you can use smarty)
  34.         $smarty->assign('res', $c);
  35.        
  36.         // or also simple echos (not recommended of course)
  37.         echo "this will be displayed on pages containing {$TOP_MENU} (if I have good memories)";
  38.     }
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment