iliketodesign Posted June 8, 2012 Share Posted June 8, 2012 What I'm trying to achieve is the following: I create a new hook, add the "featured products on the homepage" module to it and then display it on a specific CMS page using. I've updated the php file in the "featured products on the homepage" to load in my new hook rather than on the homepage. In Prestashop 1.4.x, when I wanted to register a new hook, I followed the steps in this tutorial: http://landofcoder.com/prestashop/guides/how-to-add-new-hook-in-prestashop-14.html All is well and fine in 1.5. I create a new hook, transplant the module into the hook I've created and looks to be working. But when I visit the page that should be displaying the module, I get the following error: Notice: Undefined index: HOOK_ALLPRODUCTS in /var/www/vhosts/yourlogogoeshere.ca/tckl/cache/smarty/compile/dee8cb5cf1a740316c015d6fe3db7d60bf17be67.file.cms.tpl.php on line 67 Notice: Trying to get property of non-object in /var/www/vhosts/yourlogogoeshere.ca/tckl/cache/smarty/compile/dee8cb5cf1a740316c015d6fe3db7d60bf17be67.file.cms.tpl.php on line 67 What am I doing wrong? Or can someone point me in the right direction? Link to comment Share on other sites More sharing options...
Fabien Serny Posted June 11, 2012 Share Posted June 11, 2012 Hi, The tutorial seems good. What did you put in your FrontController override ? Best regards, Link to comment Share on other sites More sharing options...
iliketodesign Posted June 11, 2012 Author Share Posted June 11, 2012 Fabien, thanks for replying. I ended up figuring it out. Initially I took the FrontController file from the tutorial (which was causing the problems) but ended up replacing the code with the following: class FrontController extends FrontControllerCore { public function initContent() { $this->process(); if ($this->context->getMobileDevice() == false) { // These hooks aren't used for the mobile theme. // Needed hooks are called in the tpl files. $this->context->smarty->assign(array( 'HOOK_HEADER' => Hook::exec('displayHeader'), 'HOOK_TOP' => Hook::exec('displayTop'), 'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''), 'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''), 'HOOK_ALLPRODUCTS' => Module::hookExec('allproducts'), )); } else { $this->context->smarty->assign(array( 'HOOK_MOBILE_HEADER' => Hook::exec('displayMobileHeader'), )); } } } adding: 'HOOK_ALLPRODUCTS' => Module::hookExec('allproducts'), Link to comment Share on other sites More sharing options...
Fabien Serny Posted June 13, 2012 Share Posted June 13, 2012 Ok great Do not hesitate if you have other questions. Link to comment Share on other sites More sharing options...
Yannkee Posted June 26, 2012 Share Posted June 26, 2012 Hello, I tried to create a new Hook in PS 1.5.0.13 following next steps to add something only after the manufacturer page. 1./ create in ps_hook INSERT INTO `ps_hook` ( `id_hook` , `name` , `title` , `description` , `position` ) VALUES ( NULL , 'afterManufacturer', 'after Manufacturer', NULL , '1' ); 2./ overide class FrontController class FrontController extends FrontControllerCore { public function initContent() { $this->process(); $this->context->smarty->assign(array( 'HOOK_HEADER' => Hook::exec('displayHeader'), 'HOOK_TOP' => Hook::exec('displayTop'), 'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''), 'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''), 'HOOK_AFTERMANUFACTURER' => Module::hookExec('aftermanufacturer'), )); } } but I do not see the hook in the positions list in BO. What's wrong ? Thanks... Link to comment Share on other sites More sharing options...
Landsman Posted December 4, 2012 Share Posted December 4, 2012 I have same problem! Anybody who know? Link to comment Share on other sites More sharing options...
the_raven Posted January 14, 2013 Share Posted January 14, 2013 (edited) i have the same problem, nobody hasn't got any Solution ? all the topics about create hooks dosn't usefull for prestashop 1.5.X !!! Edited January 14, 2013 by the_raven (see edit history) Link to comment Share on other sites More sharing options...
doubleD Posted January 30, 2013 Share Posted January 30, 2013 As far as i remember the hook is supposed to be in the prestashop database too, ps_hook table. Then it should appear in BO... Link to comment Share on other sites More sharing options...
El Patron Posted January 31, 2013 Share Posted January 31, 2013 you can add hooks dynamically within your module, see here: http://doc.prestashop.com/display/PS15/New+Developers+Features+In+PrestaShop+1.5#NewDevelopersFeaturesInPrestaShop1.5-ModuleAPI Link to comment Share on other sites More sharing options...
the_raven Posted January 31, 2013 Share Posted January 31, 2013 (edited) Make new Hook on ps 1.5 in simple 5 step : http://www.prestasho...__fromsearch__1 Edited January 31, 2013 by the_raven (see edit history) Link to comment Share on other sites More sharing options...
Fabien Serny Posted January 31, 2013 Share Posted January 31, 2013 You can create new hook in 1.5 on a easier way. I added this system since 1.5.0.7 (or one version before) In your template : {hook h='displayMyNewHook'} And in your module in your module's install method : $this->registerHook('displayMyNewHook'); Then add this method to your module : public function hookDisplayMyNewHook($params) { } No need to assign hook in controller via override anymore in 1.5 3 Link to comment Share on other sites More sharing options...
Fabien Serny Posted January 31, 2013 Share Posted January 31, 2013 And no need to add hook in database table ps_hook anymore too Link to comment Share on other sites More sharing options...
the_raven Posted January 31, 2013 Share Posted January 31, 2013 You can create new hook in 1.5 on a easier way. I added this system since 1.5.0.7 (or one version before) In your template : {hook h='displayMyNewHook'} And in your module in your module's install method : $this->registerHook('displayMyNewHook'); Then add this method to your module : public function hookDisplayMyNewHook($params) { } No need to assign hook in controller via override anymore in 1.5 yeah your method is too simple,but by this way your hook doesn't appear on Admin panel and position page..and somtimes we need to access the hook on admin panel.. Link to comment Share on other sites More sharing options...
Fabien Serny Posted January 31, 2013 Share Posted January 31, 2013 What do you mean by too simple ? For making the hook appear in you admin panel, you just have to set the flag "position" to 1 in your database. Make an override to assign a display hook in 1.5 is not a good think to do. 1 Link to comment Share on other sites More sharing options...
the_raven Posted January 31, 2013 Share Posted January 31, 2013 And no need to add hook in database table ps_hook anymore too simple mean easy and fast and maybe better than the way i suggested but you said No need to add hook in DB and if we havent the hooks on DB we cant see them on admin panel ... Link to comment Share on other sites More sharing options...
Fabien Serny Posted January 31, 2013 Share Posted January 31, 2013 I said "No need to add hook in DB" but it doesn't mean the hook is not added. I changed the code of registerHook in module class. Now when you do for example $this->registerHook('displayMySuperNewHook'); it will check if the hook exists. If not, it will add it in ps_hook. The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table. (I forgot to set this flag when I coded it). So, as I said, overriding your controller is useless and not necessary Link to comment Share on other sites More sharing options...
the_raven Posted January 31, 2013 Share Posted January 31, 2013 sorry i did your instruction and back office return me some errors: The following module(s) could not be loaded: is it possible to discribe your method with a one of prestashop defualt modules ? for example we add new DIV in header.tpl and we want to show Search modules on it. in this case as you said we need 2 files: 1- header.tpl 2- blocksearch.php is it right ? if yes please give me more detail... Link to comment Share on other sites More sharing options...
doubleD Posted January 31, 2013 Share Posted January 31, 2013 (edited) sorry i did your instruction and back office return me some errors: The following module(s) could not be loaded: is it possible to discribe your method with a one of prestashop defualt modules ? for example we add new DIV in header.tpl and we want to show Search modules on it. in this case as you said we need 2 files: 1- header.tpl 2- blocksearch.php is it right ? if yes please give me more detail... I agree, an example would be useful... I've tried it with ps 1.5.3 and "MyNewHook" wasn't added into the ps_hook table... Edit: I was wrong, there is a new hook in the ps_hook table... Edited January 31, 2013 by doubleD (see edit history) 1 Link to comment Share on other sites More sharing options...
Fabien Serny Posted February 2, 2013 Share Posted February 2, 2013 Hi, Sorry for the late answer, I saw that DoubleD saw the hook in ps_hook Do you still need an example ? Link to comment Share on other sites More sharing options...
the_raven Posted February 2, 2013 Share Posted February 2, 2013 Hi, Sorry for the late answer, I saw that DoubleD saw the hook in ps_hook Do you still need an example ? I still need the example.if its possible. i appreciate you for helping me about that. Link to comment Share on other sites More sharing options...
Fabien Serny Posted February 2, 2013 Share Posted February 2, 2013 No problem, so as I said, this only work in 1.5. In one of your template, just add the hook you want For example, index {hook h='displayMyNewHook'} Then, you can create one (or more) module with this method : /modules/mymodule/ /modules/mymodule/mymodule.php Content of mymodule.php class MyModule extends Module { function __construct() { $this->name = 'mymodule'; $this->tab = 'advertising_marketing'; $this->author = 'Your name'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Module'); $this->description = $this->l('Example of module'); } public function install() { // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook return (parent::install() AND $this->registerHook('displayMyNewHook'); } public function hookDisplayMyNewHook($params) { return 'myDisplay'; } } Now, you have "myDisplay" displayed where you put your hook. If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on. You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook. Tell me if something is not clear 7 Link to comment Share on other sites More sharing options...
SmartDataSoft Posted February 4, 2013 Share Posted February 4, 2013 No problem, so as I said, this only work in 1.5. In one of your template, just add the hook you want For example, index {hook h='displayMyNewHook'} Then, you can create one (or more) module with this method : /modules/mymodule/ /modules/mymodule/mymodule.php Content of mymodule.php class MyModule extends Module { function __construct() { $this->name = 'mymodule'; $this->tab = 'advertising_marketing'; $this->author = 'Your name'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Module'); $this->description = $this->l('Example of module'); } public function install() { // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook return (parent::install() AND $this->registerHook('displayMyNewHook'); } public function hookDisplayMyNewHook($params) { return 'myDisplay'; } } Now, you have "myDisplay" displayed where you put your hook. If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on. You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook. Tell me if something is not clear yes it work. We have build custom hook like this way last month for out one great module. Link to comment Share on other sites More sharing options...
shoulders Posted March 4, 2013 Share Posted March 4, 2013 The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table. (I forgot to set this flag when I coded it). Has this flag been added yet? Justs so i know. tar Link to comment Share on other sites More sharing options...
Fabien Serny Posted March 4, 2013 Share Posted March 4, 2013 What do you mean by "added" ? This flag is existing for a while (even in PrestaShop 1.4). It's just not set to value 1 when you create it by registering a module on it. Link to comment Share on other sites More sharing options...
shoulders Posted March 4, 2013 Share Posted March 4, 2013 (edited) Hi Fabien what i ment was, when a new hook, is registered in the new way, earlier in the thread you said: For making the hook appear in you admin panel, you just have to set the flag "position" to 1 in your database. and then you said The fact that you do not see it in your back office, it's because you have to set the flag "position" to 1 in your table.(I forgot to set this flag when I coded it). Were you going to alter the registerHook function to set the positional flag to 1. I know we can use the 'Display Non Positional Hooks' option in the backend Edited March 4, 2013 by shoulders (see edit history) Link to comment Share on other sites More sharing options...
Fabien Serny Posted March 4, 2013 Share Posted March 4, 2013 Hi, Sorry I did not understand your question at first ^^ I'm not working at PrestaShop anymore (since last july). So no, I am not going to alter the registerHook function. But you should ask for it on GitHub or on the forge. Link to comment Share on other sites More sharing options...
shoulders Posted March 4, 2013 Share Posted March 4, 2013 i will get this added to the forge. Link to comment Share on other sites More sharing options...
xezus Posted March 27, 2013 Share Posted March 27, 2013 (edited) Hi, I used this method of creating hooks but I can't display anything in this new created hook. I want display a homeslider in my new hook, but I getting message: "This module cannot be transplanted to this hook." I added my new hook into center of page <!-- Center --> <div id="center_column" class=" grid_5"> <div class="sliderPlease"> {hook h='sliderHook'} </div> then I added it into the install method in the homeslider.php if (parent::install() && $this->registerHook('displayHome') && $this->registerHook('actionShopDataDuplication') && $this->registerHook('sliderHook')) And at the bottom of the homeslider.php I added hook function public function sliderHook($params) { if(!$this->_prepareHook()) return; // Check if not a mobile theme if ($this->context->getMobileDevice() != false) return false; $this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js'); $this->context->controller->addCSS($this->_path.'bx_styles.css'); $this->context->controller->addJS($this->_path.'js/homeslider.js'); return $this->display(__FILE__, 'homeslider.tpl'); } But It's not working. The hook is installed and I can see it in BO, but I can't hook anything inside it. Please could somebody tell my what I do wrong???? Edited March 27, 2013 by xezus (see edit history) Link to comment Share on other sites More sharing options...
Fabien Serny Posted March 28, 2013 Share Posted March 28, 2013 (edited) Hi Xezus, It's because you have to rename your method hookSliderHook() instead of sliderHook() Edited March 28, 2013 by Fabien Serny (see edit history) Link to comment Share on other sites More sharing options...
xezus Posted March 28, 2013 Share Posted March 28, 2013 Omg, Thanks a lot! You saved me a hours of my live Link to comment Share on other sites More sharing options...
kalai20078 Posted March 31, 2013 Share Posted March 31, 2013 Hello Fabien, This is a useful topic. I Want to hook a module in my CMS page how can i do this with the help of your guide here. If you can guide it would be great... Thanks... Link to comment Share on other sites More sharing options...
SmartDataSoft Posted March 31, 2013 Share Posted March 31, 2013 you can read this post http://www.prestashop.com/forums/topic/763[spam-filter]hook-modules-into-cms-page/ There you will find more details. If you need more help inform me. Link to comment Share on other sites More sharing options...
kalai20078 Posted March 31, 2013 Share Posted March 31, 2013 Hi smartdatasoft Thankyou for your response i actually followed the post you have give in your response, still i cant make it work i have added a post in the below link the same ill past it here... http://www.prestashop.com/forums/topic/763[spam-filter]hook-modules-into-cms-page/page__st__20 any help would be greatly appreciated. Am using PS 1.5.3.1 I want hook a module which already installed in home page and i have duplicated the module uploaded into the modules directory. I followed exactly the same steps mentioned here in this post as followes #1. Created a hook entry in PS_Hook table (HOOK_DESIGNMYSHIRT) #2. In cms.tpl file from Module/Mymodule/cms.tpl i added the following {if ($cms->link_rewrite == 'designmyshirt')} {$HOOK_DESIGHNMYSHIRT} {/if} #3. Im cms.php file from the root directory i added the following $smarty->assign(array( 'cms' => $cms, 'HOOK_DESIGHNMYSHIRT' => Module::hookExec('designmyshirt'), // Custom hook for mycmspage 'content_only' => intval(Tools::getValue('content_only')) )); $smarty->display(_PS_THEME_DIR_.'cms.tpl'); #4. In the modules folder the module php file mymodule.php i added the following public function install(){ if (parent::install() && $this->registerHook('HOOK_DESIGHNMYSHIRT')) after at the end of this same file i added the below function function hookdesignmyshirt($params) { if ($xml = $this->_xml) { global $cookie, $smarty; $smarty->assign(array( 'xml' => $xml, 'title' => 'title_'.$cookie->id_lang, 'text' => 'text_'.$cookie->id_lang )); return $this->display(__FILE__, $this->cms.'.tpl'); } return false; } After this i installed the module and checked in the BO position. the module is displayed in the hook in BO When i check the CMS page nothing is displayed even if i configure the module from BO. I checked the Apache error log i get this following error Notice: Undefined index: HOOK_DESIGHNMYSHIRT in G:\\WAMP Server\\wamp\\www\\rave\\cache\\smarty\\compile\\e2fae568d255bdaa47e61a9405a623865dd4d436.file.cms.tpl.php on line 40, referer: http://localhost/rav...70f78b7d317be98 I want this module to be placed in center of the CMS page... Have i did everything correctly please help me to solve this issue.... Thanks.... Link to comment Share on other sites More sharing options...
Fabien Serny Posted March 31, 2013 Share Posted March 31, 2013 Hi Kalai, If you're on PrestaShop 1.5, you do not have to create an entry in ps_hook and you don't have to make modification in cms.php. You just have to follow what I'm saying on my differents posts in this topic - Add your hook in cms.tpl {hook h='designMyShirt'} - Then in your module, add the registerHook('designMyShirt') - Create in your module the method hookDesignMyShirt() Link to comment Share on other sites More sharing options...
Fabien Serny Posted March 31, 2013 Share Posted March 31, 2013 And about your error (even if you did not use the right way), your problem might comme the fact you wrote $this->registerHook('HOOK_DESIGHNMYSHIRT') instead of $this->registerHook('designmyshirt') Link to comment Share on other sites More sharing options...
kalai20078 Posted April 1, 2013 Share Posted April 1, 2013 Thanks Fabien ill give it a try... Link to comment Share on other sites More sharing options...
kalai20078 Posted April 1, 2013 Share Posted April 1, 2013 Thanks Fabien it works.... Link to comment Share on other sites More sharing options...
the_raven Posted May 12, 2013 Share Posted May 12, 2013 (edited) No problem, so as I said, this only work in 1.5. In one of your template, just add the hook you want For example, index {hook h='displayMyNewHook'} Then, you can create one (or more) module with this method : /modules/mymodule/ /modules/mymodule/mymodule.php Content of mymodule.php class MyModule extends Module { function __construct() { $this->name = 'mymodule'; $this->tab = 'advertising_marketing'; $this->author = 'Your name'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Module'); $this->description = $this->l('Example of module'); } public function install() { // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook return (parent::install() AND $this->registerHook('displayMyNewHook'); } public function hookDisplayMyNewHook($params) { return 'myDisplay'; } } Now, you have "myDisplay" displayed where you put your hook. If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on. You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook. Tell me if something is not clear hi fabien , after awhile i did your instruction and it works fine...thank you but i have one unknown problem for example made some changes to blockreinsurance module and hook it to new hook that its made with your instruction , but CSS doesn't load with new hook! as you know css load with this line : $this->context->controller->addCSS($this->_path.'style.css', 'all'); it works properly with Footer Hook ( and other hooks too ) but when i use your method css doesnt load and must to define css codes to global css. i add this div to footer.tpl : <div class="bankicon">{hook h='BankHook'}</div> and this is detail of module php : public function install() { return parent::install() && $this->installDB() && Configuration::updateValue('blockbankicon_nbblocks', 5) && $this->registerHook('BankHook') && $this->installFixtures(); } public function hookBankHook($params) { // Check if not a mobile theme if ($this->context->getMobileDevice() != false) return false; $this->context->controller->addCSS($this->_path.'style.css', 'all'); if (!$this->isCached('blockbankicon.tpl', $this->getCacheId())) { $infos = $this->getListContent($this->context->language->id); $this->context->smarty->assign(array('infos' => $infos, 'nbblocks' => count($infos))); } return $this->display(__FILE__, 'blockbankicon.tpl', $this->getCacheId()); } what you think about this issue ? Edited May 12, 2013 by the_raven (see edit history) Link to comment Share on other sites More sharing options...
Fabien Serny Posted May 13, 2013 Share Posted May 13, 2013 Hi Raven, For what I remember addCSS and addJS only works in hookHeader for 1.4 The loop which write css and js inclusion is in header.tpl and it is displayed before others hooks are called. But I thought it should work on 1.5 since a layout is present. I will test it and come back to you. 1 Link to comment Share on other sites More sharing options...
the_raven Posted May 13, 2013 Share Posted May 13, 2013 (edited) Hi Raven, For what I remember addCSS and addJS only works in hookHeader for 1.4 The loop which write css and js inclusion is in header.tpl and it is displayed before others hooks are called. But I thought it should work on 1.5 since a layout is present. I will test it and come back to you. thank you man..i appreciate you spending time for us.. but as i said, addCSS work's in 1.5 and module load css when i use other hooks , but problem occure only with new Hook that i've created with new method.. for example in this sample : public function hookFooter($params) { css load correctly... Edited May 15, 2013 by the_raven (see edit history) Link to comment Share on other sites More sharing options...
piqsel Posted May 14, 2013 Share Posted May 14, 2013 I'm also having problem with this new way of adding hooks. For example, when adding Homeslider to a new hook everything is working great except that no .css or .js files gets added. I can edit the .tpl files and see the changes so that works as it should, but when I look at the source code of the page I don't see the .css or .js files. I'm using the below method of adding files which works fine using the old way of adding hooks. $this->context->controller->addCSS($this->_path.'flexslider.css'); $this->context->controller->addJS($this->_path.'js/jquery.flexslider-min.js'); $this->context->controller->addJS($this->_path.'js/homeslider.js'); return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId()); Link to comment Share on other sites More sharing options...
Bejo Posted June 23, 2013 Share Posted June 23, 2013 Good topic Link to comment Share on other sites More sharing options...
l2c2 Posted June 25, 2013 Share Posted June 25, 2013 (edited) I'm also having problem with this new way of adding hooks. For example, when adding Homeslider to a new hook everything is working great except that no .css or .js files gets added. I can edit the .tpl files and see the changes so that works as it should, but when I look at the source code of the page I don't see the .css or .js files. I'm using the below method of adding files which works fine using the old way of adding hooks. $this->context->controller->addCSS($this->_path.'flexslider.css'); $this->context->controller->addJS($this->_path.'js/jquery.flexslider-min.js'); $this->context->controller->addJS($this->_path.'js/homeslider.js'); return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId()); Hello piqsel, You should move the css and js in the header hook /** * Header hook */ public function hookHeader($params) { global $smarty; Tools::addCSS(($this->_path).'flexslider.css', 'all'); Tools::addJS(($this->_path).'js/jquery.flexslider-min.js', 'all'); Tools::addJS(($this->_path).'js/homeslider.js', 'all'); } Edited June 25, 2013 by l2c2 (see edit history) Link to comment Share on other sites More sharing options...
maio Posted July 10, 2013 Share Posted July 10, 2013 but as i said, addCSS work's in 1.5 and module load css when i use other hooks , but problem occure only with new Hook that i've created with new method.. Hi everybody, after creating the hook the "new way" I got the same problem as Raven, in details: I created a new hook for blockreinsurance in template --> {hook h='BeforeFooter'} add to install --> && $this->registerHook('BeforeFooter'); and then defined the function: public function hookBeforeFooter($params) { return $this->hookFooter($params); } the problem is blockreinsurance.css is not being added, Link to comment Share on other sites More sharing options...
maio Posted July 11, 2013 Share Posted July 11, 2013 I used the new method to add the "block contact info" module and it works 100% , css is found in header (as usual); so it probably depends from module to module on how the css is brought in... anyway these css problems can be easily worked out, I recommend this procedure for creating hooks quickly, awesome Topic Link to comment Share on other sites More sharing options...
piqsel Posted July 13, 2013 Share Posted July 13, 2013 Hello piqsel, You should move the css and js in the header hook /** * Header hook */ public function hookHeader($params) { global $smarty; Tools::addCSS(($this->_path).'flexslider.css', 'all'); Tools::addJS(($this->_path).'js/jquery.flexslider-min.js', 'all'); Tools::addJS(($this->_path).'js/homeslider.js', 'all'); } Hi l2c2 and thank you for your help. You're right, it seems that the css and js files only gets added when they're in the headerHook. So what is the recommended way if you for example want to place the Top horizontal menu module in a custom hook? This module adds css and js files in hookDisplayTop, so should one edit the module by creating a hookHeader or create a custom hook the old way? Link to comment Share on other sites More sharing options...
syntaxed Posted August 13, 2013 Share Posted August 13, 2013 No problem, so as I said, this only work in 1.5. In one of your template, just add the hook you want For example, index {hook h='displayMyNewHook'} Then, you can create one (or more) module with this method : /modules/mymodule/ /modules/mymodule/mymodule.php Content of mymodule.php class MyModule extends Module { function __construct() { $this->name = 'mymodule'; $this->tab = 'advertising_marketing'; $this->author = 'Your name'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Module'); $this->description = $this->l('Example of module'); } public function install() { // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook return (parent::install() AND $this->registerHook('displayMyNewHook'); } public function hookDisplayMyNewHook($params) { return 'myDisplay'; } } Now, you have "myDisplay" displayed where you put your hook. If you want to see this hook in your adminpanel to have the possibility to change order of module which are hooked on. You will have (unfortunately) to go to you phpmyadmin and set the flag "position" to 1 in the table ps_hook for this hook. Tell me if something is not clear I followed the step above and got an error in my modules page at back office The following module(s) could not be loaded:: rajamodule (parse error in /modules/rajamodule/rajamodule.php) rajamodule (class missing in /modules/rajamodule/rajamodule.php) This is the hook I created in 404.tpl {hook h='404captainhook'} This is the module I created in module/rajamodule/rajamodule.php class MyModule extends Module { function __construct() { $this->name = 'mymodule'; $this->tab = 'advertising_marketing'; $this->author = 'Your name'; $this->version = '1.0'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('My Module'); $this->description = $this->l('Example of module'); } public function install() { // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hook return (parent::install() AND $this->registerHook('404captainhook'); } public function hook404captainhook($params) { return 'myDisplay'; } } Can anyone help? Link to comment Share on other sites More sharing options...
Fabien Serny Posted August 19, 2013 Share Posted August 19, 2013 Hi Syntaxed, First of all, you should name your module like your directory. Your module is in the following file : /modules/rajamodule/rajamodule.php So your class declaration should be : class RajaModule extends Module About the parse error, it's my fault, I forgot a ")" in my example. But parse error is a very common PHP error, you should have been able to detect yourself The line which contains the error is this one : return (parent::install() AND $this->registerHook('404captainhook'); You should add a ) at the end of the line return (parent::install() AND $this->registerHook('404captainhook')); Link to comment Share on other sites More sharing options...
N@D33M Posted August 26, 2013 Share Posted August 26, 2013 Hi Fabian, I'm newbie too in this arena I'm trying to add a new hook for product page, actually I wanted to copy the product price and Add to cart button + useful links (facebook, add to fav and print buttons) at the end of product page too after attributes. There are pb-right-column and pb-left-column for price and useful links. I don't want to hack the core but wanted to create our own hook so in future if we wanted to remove that think, we can simply unhook from BO. What I figured out is to create a manual entry in ps_hooks table (I'm using PS 1.5.4) Wanted to override the frontController file by definging another class in override/front/frontOverrideClass there I'll be defining a new line of code with my newPositionHook under initContent() function then I'll be using that smarty assigned variable for newPositionHook in proudct.tpl page and using it at the bottom of products attribute content where I wanted to show that new things. Please guide me am I doing that right so is there any clean solution for that? Thanks, Nadeem Link to comment Share on other sites More sharing options...
Fabien Serny Posted August 28, 2013 Share Posted August 28, 2013 Hi, Please reread this topic, I explained the best way to do what you want to do here : http://www.prestashop.com/forums/index.php?/topic/173027-solved-how-to-create-a-new-hook-in-15-am-i-doing-it-wrong/page__view__findpost__p__1093404 No need to insert a manual entry in ps_hook table, no need to make an override. Link to comment Share on other sites More sharing options...
maio Posted October 18, 2013 Share Posted October 18, 2013 I added a new hook with the new way: {hook h='LeftFooter'} and then on the module (block contact info) i added && $this->registerHook('LeftFooter') and public function hookLeftFooter($params) { return $this->hookFooter($params); } And it had worked perfectly but... recently I changed my shop url directory folder and I couldn't get the module template to update in anyway --while every other module was working correctly...... To make it work I had to eliminate it and reinstall, no big deal but still it behaved differently than other module+hooks 1 Link to comment Share on other sites More sharing options...
Fabien Serny Posted October 21, 2013 Share Posted October 21, 2013 Hi, Very strange, changing your shop url should not impact on module template.Are you sure it was not a cache problem or anything else like that ? I'll make a test to check this. Fabien Link to comment Share on other sites More sharing options...
maio Posted October 22, 2013 Share Posted October 22, 2013 I went over it again, and now it's working correctly, maybe your right... thanks anyway Link to comment Share on other sites More sharing options...
malyo Posted December 1, 2013 Share Posted December 1, 2013 (edited) Hello everyone, I have a problem - i want to add user info module to newly created hook, but prestashop says it can't be moved to this hook. Any ideas? Edited December 3, 2013 by malyo (see edit history) Link to comment Share on other sites More sharing options...
maio Posted December 20, 2013 Share Posted December 20, 2013 (edited) in your blockuserinfo.php you need to modify public function... find public function hookTop($params){ ........ ........ ........} and change it to public function hookNEWHOOK($params) { ........... .. . . . . .} Your hook should work now, --- you can also find another hint to visualize your new hook in the backoffice/module/position , read Fabien's post #21 Edited December 20, 2013 by maio (see edit history) Link to comment Share on other sites More sharing options...
imooch Posted January 22, 2014 Share Posted January 22, 2014 (edited) hi thanks i landed on this page from here http://nemops.com/adding-hooks-to-prestashop-1-5/#.UuCfWPuIa1t I worked but it changed the appearance of the footer Any ideas how this can be improved? Edited January 22, 2014 by imooch (see edit history) Link to comment Share on other sites More sharing options...
Kogkalidis Posted January 23, 2014 Share Posted January 23, 2014 Does it WORK properly? If so just change the css of the newsletter as I see that everything else looks good! Link to comment Share on other sites More sharing options...
imooch Posted January 23, 2014 Share Posted January 23, 2014 Does it WORK properly? If so just change the css of the newsletter as I see that everything else looks good! Thank you very much for the swift reply It does work properly the only problem is the css which i could not figure out what to enter or even where to enter it.I spent three hours on it and in the end i left it looking that way. i was using firebug I noticed somewere in this thread you had said something about the css http://www.prestashop.com/forums/topic/241012-solvedhow-do-i-move-the-newsletter-block-to-the-footer/ could you please tell me what i need to write in the css files. Link to comment Share on other sites More sharing options...
Kogkalidis Posted January 23, 2014 Share Posted January 23, 2014 just right click -> inspect element -> check where the corresponding css is located & play with the settings for the desired result -> just copy&paste the changes in the file and refresh Link to comment Share on other sites More sharing options...
cupcakes Posted February 22, 2014 Share Posted February 22, 2014 Does this work in the latest Prestashop? Link to comment Share on other sites More sharing options...
mdusamaansari Posted February 28, 2014 Share Posted February 28, 2014 (edited) Hi Techies, I am using Prestashop version 1.5.6.2. In my product-list.tpl I have this code <div id="prod_list">{hook h='myOwnHook' idproduct=$product.id_product}</div> In my module folder myownhook.php file contains public function hookMyOwnHook($params) { $id_product = $params['idproduct']; if($id_product) { $product_info = $id_product; $smarty->assign('product_info', $product_info); return $this->display(__FILE__, 'myownhook.tpl'); } } In my myownhook.tpl file <div id="myownhook">{$product_info}</div> I am not getting anything on my product-list.tpl. Edited February 28, 2014 by mdusamaansari (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted February 28, 2014 Share Posted February 28, 2014 hello does the $id_product variable exist after $id_product = $params['idproduct']; can you please verify it? Link to comment Share on other sites More sharing options...
mdusamaansari Posted March 3, 2014 Share Posted March 3, 2014 hello does the $id_product variable exist after $id_product = $params['idproduct']; can you please verify it? Hi Vekia, The .tpl file contains <div id="prod_list">{hook h='myOwnHook' idproduct=$product.id_product}</div> I hope $product.id_product contains the variable value. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted March 3, 2014 Share Posted March 3, 2014 Hello, have face this kind of issue. IF you passed product id and on custom hook . It only work on product-list.tpl If you put this on any home page module and it is cached there wrong data comes. I have do this to show product ratting. If there is no ratting on some product , it show the previous product ratting Here is my code {hook h='displaySdsAfterProductName' idproduct=$product.id_product} and bellow code is run on php file public function hookDisplaySdsAfterProductName($params) { global $smarty ; if(!isset($params['idproduct']) OR empty($params['idproduct'])) return 'No ID'; require_once(_PS_MODULE_DIR_.'/productcomments/ProductComment.php'); require_once(_PS_MODULE_DIR_.'/productcomments/ProductCommentCriterion.php'); $id_product = $params['idproduct']; $product_average = 0; $grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id); $criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id); $grade_total = 0; if (count($grades) > 0) { foreach ($criterions as $criterion) { if (isset($grades[$criterion['id_product_comment_criterion']])) { $grade_total += (float)($grades[$criterion['id_product_comment_criterion']]); } } $product_average = $grade_total / count($criterions); } $this->context->smarty->assign('average_total', (int)$product_average); return $this->display(__FILE__,'views/templates/front/single_product_rating.tpl'); } I used this to show product ratting in my Sellya theme. Link to comment Share on other sites More sharing options...
tdc666 Posted March 5, 2014 Share Posted March 5, 2014 is it possible to put in a hook to call an existing mod? my index is mostly custom html, but i want to insert the featured products module in there, how would i go about that? Link to comment Share on other sites More sharing options...
vekia Posted March 5, 2014 Share Posted March 5, 2014 you can't call module, you can call only hooks so create custom hook, attach there your module, then call this hook Link to comment Share on other sites More sharing options...
Yoeba Posted March 6, 2014 Share Posted March 6, 2014 Hi, I followed the steps to create new hooks described by Fabien. Everything works on localhost but not on-line. The module is not loaded in the new hook... Can you help me? Thanks! Link to comment Share on other sites More sharing options...
gfstudio Posted April 9, 2014 Share Posted April 9, 2014 I tried to create my custom module and hook using the following code but when i gp to module page i get the following error, in italian Il modulo seguente (s) non è stato possibile caricare:mymodule (errore di analisi in /modules/mymodule/mymodule.php) mymodule (classe mancante in /modules/mymodule/mymodule.php) It says the module has not been loaded. 1) analisys error 2) missing class Any idea of the problem ? class MyModule extends Module{function __construct(){$this->name = 'mymodule';$this->tab = 'advertising_marketing';$this->author = 'Your name';$this->version = '1.0';$this->need_instance = 0;parent::__construct();$this->displayName = $this->l('My Module');$this->description = $this->l('Example of module');}public function install(){ // Here the registerHook method will check if the hook exists, if not it will add it to table ps_hookreturn (parent::install() AND $this->registerHook('displayMyNewHook');}public function hookDisplayMyNewHook($params){ return 'myDisplay';}} Link to comment Share on other sites More sharing options...
Fabien Serny Posted December 9, 2014 Share Posted December 9, 2014 Hi Yoeba, Can you post your code ? Maybe I'll be able to help you Hi Gfstudio, I'm sure you figured out what your problem was (since your post was 6 month ago). But in fact you just forgot a ) return (parent::install() AND $this->registerHook('displayMyNewHook'); should have been return (parent::install() AND $this->registerHook('displayMyNewHook')); Link to comment Share on other sites More sharing options...
ps20 Posted September 30, 2015 Share Posted September 30, 2015 thank you Link to comment Share on other sites More sharing options...
sondiva Posted December 29, 2015 Share Posted December 29, 2015 Hi Fabien Serny Recently I bought a module to show delivery dates and time-frame slots for customers it works well in front (website) but when I made a custom hook and and tried to call the hook into back-end admin , manual new order it does not shows up. The hook installed in database ps_hooks perfectly here is the code i used to install ---------------------------------------------------------- public function install() { if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { $before_carrier = method_exists('Hook', 'get') && Hook::get('beforeCarrier'); } else { $before_carrier = true; } if (!$this->samdha_tools->executeSQLFile(self::INSTALL_SQL_FILE) || !parent::install() || !($before_carrier?$this->registerHook('beforeCarrier'):true) || !$this->registerHook('footer') || !$this->registerHook('header') || !$this->registerHook('adminOrder') || !$this->registerHook('GoDate') || (version_compare(_PS_VERSION_, '1.5.0.0', '>=')?!$this->registerHook('displayPDFInvoice'):false) || (version_compare(_PS_VERSION_, '1.5.0.0', '>=')?!$this->registerHook('displayPDFDeliverySlip'):false) || !$this->registerHook('newOrder')) { return false; } return true; } public function hookGoDate($params) { return $this->display(__FILE__, 'deliverydays.tpl'); } Link to comment Share on other sites More sharing options...
Fabien Serny Posted December 29, 2015 Share Posted December 29, 2015 Hi Sondiva, Where do you call this new hook ? And how do you do it ? Can you copy / paste the code ? Fabien Link to comment Share on other sites More sharing options...
sondiva Posted December 29, 2015 Share Posted December 29, 2015 I call this into controllers\orders\form.tpl Link to comment Share on other sites More sharing options...
Fabien Serny Posted December 29, 2015 Share Posted December 29, 2015 Can you copy / paste the code ? Link to comment Share on other sites More sharing options...
sondiva Posted December 29, 2015 Share Posted December 29, 2015 Ok Luckily i managed to get hook into form.tpl, but date selection is not active...is it jquery issue?? see the attachment Link to comment Share on other sites More sharing options...
Fabien Serny Posted December 29, 2015 Share Posted December 29, 2015 It's difficult to answer without seeing the code. Do you have any JS error reported by your browser ? Link to comment Share on other sites More sharing options...
sondiva Posted December 29, 2015 Share Posted December 29, 2015 no error reported but i can't select the date in backend whereas i can select the date and timeframe from front end while checking out I will PM u the code Link to comment Share on other sites More sharing options...
Fabien Serny Posted December 29, 2015 Share Posted December 29, 2015 I answered you in PM Link to comment Share on other sites More sharing options...
Dadachacha Posted November 10, 2016 Share Posted November 10, 2016 Bonjour Fabien, Ca fait 2 fois que ma boutique saute et le pb que tu soulèves ressemble au mien... enfin je crois. En fait dans le back office j'ai voulu tester la remise sur un groupe de clients. Je me suis mis donc dedans avec mon adresse d'administrateur et lorsque j'ai validé j'ai eu un étrange message rouge. Comme c'est pas le 1er que je vois, j'ai quitté la session et lorsque je me suis connecté sur le site et rentré mes identifiants/MDP, le site a sauté et pour TOUS les clients qui se loguent. Par contre pour les visiteurs, le site paraît normal. Du coup je suis retourné sur le backoffice et j'ai remis les mêmes paramètres que j'avais à la base dans ma fiche clients et hop le site refonctionne. Voici le type de lignes que j'avais sur ma home lorsque le site avait sauté: "Undefined index:HOO_BLOCKPOSITION1 in /homepages/42/...." " Notice:Trying to get property of non-object in/homepages/42/..." Et j'ai ensuite le même genre pour le HOOK_BLOCKFOOTER1 et HOOK_BLOCKFOOTER3 Merci de ton aide Fabien Link to comment Share on other sites More sharing options...
Fabien Serny Posted November 15, 2016 Share Posted November 15, 2016 Hi Dachacha, This is not an issue related to this post.I'll answer you in PM Best regards, Fabien Link to comment Share on other sites More sharing options...
Recommended Posts