Dhen Bagoez Posted February 1, 2011 Share Posted February 1, 2011 Hello.....I have a problem how to Creat new 'HOOK' in prestashop 1.4, Where are the hooks defined?in previous versions (1.3) I attach the code in 'header.php' and in theme/'header.tpl'.anyone please help... Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted February 2, 2011 Share Posted February 2, 2011 It's the same as 1.3, but in 1.4 you have "Controllers". So here you can attach the code at "FrontController". 1 Link to comment Share on other sites More sharing options...
thefamilymovers Posted February 2, 2011 Share Posted February 2, 2011 sorry I am too new on this forum so please any one can help us...? Link to comment Share on other sites More sharing options...
Dhen Bagoez Posted February 2, 2011 Author Share Posted February 2, 2011 thanks 'UltraWebDev' for your answerbut could you please tell me location of 'FrontController' file?thank you Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted February 2, 2011 Share Posted February 2, 2011 classes/FrontController.php Link to comment Share on other sites More sharing options...
Dhen Bagoez Posted February 2, 2011 Author Share Posted February 2, 2011 ok, our new hook named is HOOK_CENTERI attach the code in header.tpl {$HOOK_CENTER} and attach in classes/FrontController.php in line:394 'HOOK_CENTER' => Module::hookExec('center'), the problem is: How to appear a new HOOK in Back Office > Modules Positions page?that appears also to be used for transplant module column.sorry for my bad English ;-P thanks Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted February 3, 2011 Share Posted February 3, 2011 In order to see your hook there, it must be in the "ps_hook" DB table . Link to comment Share on other sites More sharing options...
Paul C Posted February 5, 2011 Share Posted February 5, 2011 You should also NOT be modifying the classes/FrontController.php file at all, but providing an override as `override/classes/FrontController.php`The override file could be as simple as (untested): <?php class FrontController extends FrontControllerCore { function displayHeader() { parent::displayHeader(); $this->smarty->assign(array('HOOK_CENTER' => Module::hookExec('center'))); } } As mentioned you also need to add an entry in the database table, so you can actually use it.Paul 3 Link to comment Share on other sites More sharing options...
Dhen Bagoez Posted February 6, 2011 Author Share Posted February 6, 2011 excellent! Thanks 'Paul'. Your directions as I expected. I will try it...... Link to comment Share on other sites More sharing options...
ometiclan Posted February 6, 2011 Share Posted February 6, 2011 ok.. maybe i'm missing something, but i can't get my new hook to work.I have 1. added a new Hook in my DB called "lala"2. made a new file in override/classes/ called Frontcontroller.php3. added <?php class FrontController extends FrontControllerCore { function displayHeader(){ parent::displayHeader(); $this->smarty->assign(array('HOOK_LALA' => Module::hookExec('lala'))); } } ?> to FrontController.php4. added {$HOOK_LALA} to my header.tplBUT... nothing is happening. I got the hook displayed in the back end but when i add modules they aren't displayed on my page... Any suggestions? I'm pretty clueless right now. I really like PrestaShop but the Hook-System sucks. It's a core function in templating that should be MUCH simpler to implement. Link to comment Share on other sites More sharing options...
Paul C Posted February 7, 2011 Share Posted February 7, 2011 I think this could be down to a slight misunderstanding as to how hooks work; as to actually display anything the module you're hooking in must support the hook and I'm not sure you have done that?In your module install() function you would execute (OR you can do nothing in the module and rely on the Backoffice "transplant" functionality which does exactly the same thing): $this->registerHook('lala'); But in your module class you would always need to implement: public function hookLala($params) { echo 'la,la,la,la,la'; } If you had used: $this->smarty->assign(array('HOOK_LALA' => Module::hookExec('leftColumn'))); Then you could transplant any module that "supports" rendering to the left column to the hook "lala". The support in the module relies on a public member function that is named "hook", which in this case is "hookLala" (by convention the first letter of your hook name is made upper case - no idea why.... "hooklala" may in fact work just the same and the case may be ignored - haven't ever tried I don't think).Paul Link to comment Share on other sites More sharing options...
ometiclan Posted February 7, 2011 Share Posted February 7, 2011 Hi Paul!Thank you for your answer. as to actually display anything the module you’re hooking in must support the hook and I’m not sure you have done that? I figured that out myself at 04:00 this morning after roughly 5 hours of searching for an answer. And yes, you are right, i didn't put the proper function in the modules i wanted to display at my hook (btw: it's not case sensitive, hookLulu and hooklulu both work).Prestashop is pretty neat, but as stated before - the hook system needs some serious improvement IMO. To display the category-block in a custom area you need to modify1. the header.tpl2. the header.php3. the FrontController.php AND4. the blockcategories.php... that's a rediculous amount of work just to display a module! Compared to other CMS (yes i know, it's not a CMS, it's a shopsystem) like Expression Engine, where you can put rendering-commands like {exp:comment:entries} anywhere you want or Wordpress, where you just drag and drop your widget to the proper Sidebar, Prestashop needs improvement. Link to comment Share on other sites More sharing options...
Paul C Posted February 7, 2011 Share Posted February 7, 2011 @ometiclan I've just published an article on my site you find interesting regarding using theme plugins as an alternative to hooks for module output in Prestashop 1.4.It seems to work for me in the case of adding the home featured products output at the bottom of cms pages, and saves a lot of work and messing about with custom hooks and database changes.Paul Link to comment Share on other sites More sharing options...
rkinfo Posted February 21, 2011 Share Posted February 21, 2011 I think this could be down to a slight misunderstanding as to how hooks work; as to actually display anything the module you're hooking in must support the hook and I'm not sure you have done that?In your module install() function you would execute (OR you can do nothing in the module and rely on the Backoffice "transplant" functionality which does exactly the same thing): $this->registerHook('lala'); But in your module class you would always need to implement: public function hookLala($params) { echo 'la,la,la,la,la'; } If you had used: $this->smarty->assign(array('HOOK_LALA' => Module::hookExec('leftColumn'))); Then you could transplant any module that "supports" rendering to the left column to the hook "lala". The support in the module relies on a public member function that is named "hook", which in this case is "hookLala" (by convention the first letter of your hook name is made upper case - no idea why.... "hooklala" may in fact work just the same and the case may be ignored - haven't ever tried I don't think).Paul Paul you're a helpful poster but I've noticed that neither on your blog or your forum - you never post what file or line the code in reference is supposed to be. What gives Link to comment Share on other sites More sharing options...
Paul C Posted February 22, 2011 Share Posted February 22, 2011 Well in most cases that's because the discussion is about general development issues. In this thread, for example, It's impossible to specify what the filename or the linenumber to modify in ometical's example would be as he doesn't specify which module(s) he would like to hook, and we're talking about adding a new class member function (the choice of where it's added would be up to the person making the change - it could be anywhere in the class definition).In all honesty I'm not likely to tell anyone which Prestashop core files to hack to get something to work, as that is just setting them up to spend hours asking questions on here later when they next try and upgrade and find that they can't. I have always taken the approach that none of the core files should ever be modified to produce custom behaviour; and if you're going to modify them, then you should know what you're doing and not have to ask or you'll be forever dependent upon others goodwill to bail you out.Another issue is that for many of the core supplied modules the version numbers haven't been updated even though the actual code in the modules has changed (through bug fixes - some of which have been major). This means that unless you have exactly the same "version 1.1" of the module that's under discussion, then the line numbers (and some of the specific code quoted) will be meaningless.In saying the above, if there's ever a case where you feel that any of the information I supply is insufficient, then you can always ask for clarification and I may or may not notice and reply Paul Link to comment Share on other sites More sharing options...
rkinfo Posted February 22, 2011 Share Posted February 22, 2011 That's cool dude. It would be helpful though if you gave some indicator of what you're talking about though i.e. "right after the function hookRightColumn($params){ }you know cause people are equally willing to try and guess what line of code you're referring to and mess it up all the same Link to comment Share on other sites More sharing options...
Paul C Posted February 22, 2011 Share Posted February 22, 2011 Fair comment. I'll try and be more newbie friendly in future Paul Link to comment Share on other sites More sharing options...
smashit Posted March 19, 2011 Share Posted March 19, 2011 Hi Paul,When I assign a new hook to header.tpl in the FrontControllerCore class it works.But when i try to override it in (override/classes/FrontController.php) the new hook isn't assigned : class FrontController extends FrontControllerCore { public function displayHeader() { parent::displayHeader(); $this->smarty->assign(array('HOOK_NAV_BAR' => Module::hookExec('navBar'))); } } The overriding class is taken in account. I tried to copy entire core class to overriding class and assign new hook and it works as well.But as it's not clean to override all class since I need just a part of a function to be overrided, i'm looking for a solution.Thx for you answers. Link to comment Share on other sites More sharing options...
BeeR Posted March 19, 2011 Share Posted March 19, 2011 Hello. I did all the modyfiactions but that did not work. New hook just didn`t appear. I need something like that on picture above. That center, crossed area. Link to comment Share on other sites More sharing options...
Burhan BVK Posted March 19, 2011 Share Posted March 19, 2011 You have to call the displayHeader function after assigning the new hook. Hi Paul,When I assign a new hook to header.tpl in the FrontControllerCore class it works.But when i try to override it in (override/classes/FrontController.php) the new hook isn't assigned : class FrontController extends FrontControllerCore { public function displayHeader() { parent::displayHeader(); $this->smarty->assign(array('HOOK_NAV_BAR' => Module::hookExec('navBar'))); } } The overriding class is taken in account. I tried to copy entire core class to overriding class and assign new hook and it works as well.But as it's not clean to override all class since I need just a part of a function to be overrided, i'm looking for a solution.Thx for you answers. 1 Link to comment Share on other sites More sharing options...
BeeR Posted March 19, 2011 Share Posted March 19, 2011 When i make that override the center column and right column dissaper.I`ve adde to DB ps_hook: id 67, slider, slider (desc)I`ve added to header.tpl ..... <!-- Left --> {$HOOK_LEFT_COLUMN} <- here {$HOOK_SLIDER} <- & here <- & here <!-- Center --> { {/if} 9 Link to comment Share on other sites More sharing options...
smashit Posted March 19, 2011 Share Posted March 19, 2011 Thank you, it works now Link to comment Share on other sites More sharing options...
BeeR Posted March 19, 2011 Share Posted March 19, 2011 @smashit could you post that files that you make some changes to download ? Link to comment Share on other sites More sharing options...
smashit Posted March 20, 2011 Share Posted March 20, 2011 Well it seems that you don't override anything since you modfied FrontController.php file.Sending my files won't help you.Is there any errors displayed ?If not are you sure you enabled the display of errors? @ini_set('display_errors', 'on'); Link to comment Share on other sites More sharing options...
xacoso Posted March 23, 2011 Share Posted March 23, 2011 @ometiclan I've just published an article on my site you find interesting regarding using theme plugins as an alternative to hooks for module output in Prestashop 1.4.It seems to work for me in the case of adding the home featured products output at the bottom of cms pages, and saves a lot of work and messing about with custom hooks and database changes.Paul Paul C, that article you published just saved my life !!!I was struggling with hooks for showing the "JQuery Nivo Slider" inside the "header.tpl" of my template, but used you code files and added the line:{plugin module='slideric' hook='home'} Inside "header.tpl", and it just worked perfectly!!!You can see the result here: http://www.elpalaciodelsexo.com/ (site is still work in progress)Regards! Link to comment Share on other sites More sharing options...
Sundbox Posted March 29, 2011 Share Posted March 29, 2011 Hi!I use the Paul's solution and it's works fine, but I'm trying to make the same thing that xacoso but in his shop http://www.elpalaciodelsexo.com/ when you go away from the homepage (category, product page, etc) the slider does not appear. In my shop the slider is always is showed.I'm using the same code in header.tpl {$HOOK_TOP} {plugin module='slideric' hook='home'} <!-- Left --> {$HOOK_LEFT_COLUMN} There is some more code that it should modify?Maybe a specific configuration in "Positions" in backoffice? Link to comment Share on other sites More sharing options...
Paul C Posted March 29, 2011 Share Posted March 29, 2011 There should be a smarty variable {$page_name} defined - it's used in the <body> tag in header.tpl to use as the id for the body of each page. I think you could test that to see if you are on the index page e.g. {$HOOK_TOP} {if isset($page_name) AND $page_name=='index'} {plugin module='slideric' hook='home'} {/if} <!-- Left --> {$HOOK_LEFT_COLUMN} Link to comment Share on other sites More sharing options...
Sundbox Posted March 29, 2011 Share Posted March 29, 2011 Great! I Tried this solution but it did not know the variable. Thanks so much Paul! Link to comment Share on other sites More sharing options...
Sundbox Posted March 29, 2011 Share Posted March 29, 2011 A little tip: In this situation div can't be id="slider" because it enters conflict with the class of the module and the module don't works fine.This is my final code: {if isset($page_name) AND $page_name=='index'} {plugin module='slideric' hook='home'} {/if} Link to comment Share on other sites More sharing options...
leelee23 Posted April 3, 2011 Share Posted April 3, 2011 You have to call the displayHeader function after assigning the new hook. I think I'm being a bit thick here! I have the same problem as smashit had, but I'm wondering where I have to call the displayHeader function? And if so, how? lol Link to comment Share on other sites More sharing options...
Romeo.Tran Posted April 14, 2011 Share Posted April 14, 2011 Hello All,I wrote a new sort guide to add new hook in prestashop 1.4 use my lofslider module.Here is link:http://landofcoder.com/download/guides-docs/docs-guide-prestashop/128-how-to-add-new-hook-in-prestashop-14.htmlIf someone has time please comment to i can get best solution for adding new hook in prestashop 1.4.Best Regards. Link to comment Share on other sites More sharing options...
A-Z Hosting Posted April 16, 2011 Share Posted April 16, 2011 Hi Paul!Prestashop is pretty neat, but as stated before - the hook system needs some serious improvement IMO. To display the category-block in a custom area you need to modify1. the header.tpl2. the header.php3. the FrontController.php AND4. the blockcategories.php How do we make this entire process upgrade safe? I know if we add overrides/classes/FrontController.php that file will be fine and if we put header.tpl into the themes/mytheme/ it will be safe too. However, so far I can't tell that there is a safe way to modify 2 and 4 in an upgrade safe manner. By the way good thread. I've been through the boards quite thoroughly (at least the english ones) and this is the best one on adding a new Hook. [applause]Wil Link to comment Share on other sites More sharing options...
Dhen Bagoez Posted May 4, 2011 Author Share Posted May 4, 2011 thanks for allespecially to Paul c and Romeo.Tran. for their explanation.My new HOOK has been able to work well here ;-) Link to comment Share on other sites More sharing options...
uddhava Posted May 12, 2011 Share Posted May 12, 2011 @ometiclan I've just published an article on my site you find interesting regarding using theme plugins as an alternative to hooks for module output in Prestashop 1.4.Paul I noticed on your website that your plugin solution, which is super great btw, only will work on Smarty v2. Any change on releasing a 1.4.2 compatible plug ? Link to comment Share on other sites More sharing options...
uddhava Posted May 13, 2011 Share Posted May 13, 2011 Well it seems that you don't override anything since you modfied FrontController.php file.Sending my files won't help you.Is there any errors displayed ?If not are you sure you enabled the display of errors? @ini_set('display_errors', 'on'); Since nobody has offered a working override example i started another thread to find out how to use the override code correctly. See here : http://www.prestashop.com/forums/viewthread/109195 Link to comment Share on other sites More sharing options...
edyy Posted July 29, 2011 Share Posted July 29, 2011 Great article paul , after reading a few threds I manage to do this with the help of your article. Thanks Link to comment Share on other sites More sharing options...
diamondf Posted January 20, 2012 Share Posted January 20, 2012 Hey guys I'm having the same problem with the block search top...i`m trying to move it to a new hook that i created....its called 'headerSearch' ....i attached it to header.tpl....i added the new hook in db.. and i modified the blocksearch.php by adding the new hook in the source line 53 OR !$this->registerHook('headerSearch') line 87-91 public function hookheaderSearch($params) { $this->_hookCommon($params); return $this->display(__FILE__, 'blocksearch-top.tpl'); } aftere that i transplanted it to the new hook....but the module it doesnt appear in the new hook what should I do?! Link to comment Share on other sites More sharing options...
sayantan Posted January 21, 2012 Share Posted January 21, 2012 I want a news panel for my prestashop HOME PAGE in body section. sorry I am too new on this forum so please any one can help us for this requirement...? Link to comment Share on other sites More sharing options...
PariGupta Posted June 15, 2012 Share Posted June 15, 2012 Hi Paul, I m new in prestashop. I want to know if i want to add an extra functionality after user login then how i can do this. please tell me step by step process. I need the help. Link to comment Share on other sites More sharing options...
mkli73 Posted September 25, 2014 Share Posted September 25, 2014 You should also NOT be modifying the classes/FrontController.php file at all, but providing an override as `override/classes/FrontController.php` The override file could be as simple as (untested): <?phpclass FrontController extends FrontControllerCore{ function displayHeader() { parent::displayHeader(); $this->smarty->assign(array('HOOK_CENTER' => Module::hookExec('center'))); [spam-filter] As mentioned you also need to add an entry in the database table, so you can actually use it. Paul Hello dear Paul, I am trying in adding a new hook i my prestashop6 ,so I am doing the following steps: 1. The name of my hook is bottom 2. I have added the hook in my ps_table name: displayBottom title: displayBottom 3.created the FrontController.php like this: <?php class FrontController extends FrontControllerCore{ function displayBottom() { parent::displayBottom(); $this->smarty->assign(array('HOOK_BOTTOM' => Module::hookExec('bottom'))); [spam-filter] 4. I uploaded in the following directory override/classes/controller Then I go in the Theme configurator in my presta shop and the only hooks I see in the page are the top,left, right and footer. Will it be possible to let me know what I am doing wrong. Thanks in advance Marina 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