Jump to content

Custom hook


Recommended Posts

HI all,

 

I'm a newbie at Prestashop. I've been trying to move the Top Menu to a new div I wanted to create because of design purposes. For that, I understand I need a new hook. I've been looking online and all the tutorials seem to be missing a piece or it's for 1.5. It's confusing as hell and in the 4 hours of struggle, I could not make my custom hook work.

 

1. so I added a new hook in the database ps_hook

name: displayMainMenu

 

2.  I overwrite my blocktopmenu php in override/classes/module

 

<?php
 
class BlocktopmenuMainMenu extends Blocktopmenu
{
 
public function install()
{
if (
!parent::install() ||
!$this->registerHook('displayMainMenu')
)
return false;
return true;
}
 
 public function hookDisplayMainMenu($params)
    {
        return $this->hookMainMenu($params);
    }
}

?> 

 

3. I overwrite my Front Controller php  in override/controllers/front

 

<?php
 
class FrontController extends FrontControllerCore
{
 
    public function initContent()
    {
        parent::initContent();
 
        $this->context->smarty->assign(
            'HOOK_MAIN_MENU', Hook::exec('displayMainMenu')
        );
    }
}
 

?>

4. I add the hook to my header.tpl
 

{if $HOOK_MAIN_MENU}
<div id="main-menu">
{$HOOK_MAIN_MENU}
</div>
{/if}

The back office shows my new hook but it won't transplant the menu to it. So I tested the code in core file and it transplants it successfully but the menu doesn't show up in the front office. I want to do it properly so overwriting, so if I do that, it won't transplant AND it won't show up.
 
What am I doing wrong or can somebody point me to a good tutorial that isn't chaotic and confusing?

Thanks in advance.
Edited by d4rkbl4de (see edit history)
Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...