Jump to content

[SOLVED] Create new hook in the header for blocktopmenu


Recommended Posts

  • 3 weeks later...

 

in header.tpl yes work  but , themes/name/blocktopmenu not work 


	<!-- Menu -->
	<div id="block_top_menu" class="sf-contener clearfix col-lg-12">
		<div class="cat-title">{l s="Categories" mod="blocktopmenu"}</div>
		<ul class="sf-menu clearfix menu-content">
        
			{$MENU}
			{if $MENU_SEARCH}
				li class="sf-search noBack" style="float:right">
					<form id="searchbox" action="{$link->getPageLink('search')|escape:'html':'UTF-8'}" method="get">
						<p>
							<input type="hidden" name="controller" value="search" />
							<input type="hidden" value="position" name="orderby"/>
							<input type="hidden" value="desc" name="orderway"/>
							<input type="text" name="search_query" value="{if isset($smarty.get.search_query)}{$smarty.get.search_query|escape:'html':'UTF-8'}{/if}" />
						</p>
					</form>
				</li>
                
			{/if}
            
   <!--principio inicio sesion-->         
            {if $is_logged}
	<li>
		<a href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}" title="{l s='View my customer account'  mod="blocktopmenu"}" class="account" rel="nofollow"><span><!--{$cookie->customer_firstname} {$cookie->customer_lastname}-->{l s='Mi cuenta'  mod="blocktopmenu"}</span></a>
	</li>
{/if}
<li>
	{if $is_logged}
		<a class="logout" href="{$link->getPageLink('index', true, NULL, "mylogout")|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Log me out'  mod="blocktopmenu"}">
			{l s='Salir'  mod="blocktopmenu"}
		</a>
	{else}
		<a class="login" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Login to your customer account'  mod="blocktopmenu"}">
			{l s='Entrar'  mod="blocktopmenu"}
		</a>
	{/if}
</li><!--fin inicio sesion-->  
<!-- /Block usmodule NAV -->
<li><a>carrito{$HOOK_CARRITO}</a></li>
		</ul>
	</div>
	<!--/ Menu -->

post-319618-0-06858800-1399489806_thumb.jpg

Edited by Ron morales (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

forgive me if I can't explain myself properly, I am a newbie to PS!

I am making some training/testing with PS 1.6.
I dowloaded a module called Configurable Header Links. It displays link titles, arranged horizontally.
It automatically goes hooked to displayTop.

Instead, I want to hook it at the very top of the page, where the block banner is (ideal would be that it overlays the banner, and is displayed in a layer above the banner itself. However, being displayed at the very top, and then the banner will be ok as well!!)

Is it possibile?

How?

I tried to hook it to displayHeader and put in as first element in that hook, but nothing. I also tried to hook it to displayBanner. which is the only other hook to which the block banner was hooked, but that isn't allowed...

How can I do?

Consider I am a total dummy with coding, so the easiest it is, the better!

Thanks!

Elisa

Edited by elisa.foschini (see edit history)
Link to comment
Share on other sites

  • 2 months later...

 

create new hook in your prestashop database, for example with name "AfterTop"

 

then in module php file use this function:

public function hookAfterTop($params){
return $this->hookDisplayTop($params);
}

I did this and and the menu is in the right location but superfish-modified .css is not loading or something.  The menu displays as plain text and when I inspect element superfish is not there.

Link to comment
Share on other sites

Hi vekia, I'm trying to use your method for moving the tophorizontalmenu in a different position.

 

1. I started creating a new field named "AfterTop" in table "ps_hook".

 

Now where i should place this code? 

public function hookAfterTop($params){
return $this->hookDisplayTop($params);
}

In blocktopmenu.php file?

 

And then which code i should use in my header tpl file to add the hook?

Link to comment
Share on other sites

public function hookAfterTop($params){
return $this->hookDisplayTop($params);
}

In blocktopmenu.php file?

 

that's right, in blocktopmenu.php file, add it like other hook functions, 

you can place code before last closing bracket }

 

 

 

 
And then which code i should use in my header tpl file to add the hook?

 

{hook::exec('AfterTop')}

Link to comment
Share on other sites

that's right, in blocktopmenu.php file, add it like other hook functions, 

you can place code before last closing bracket }

 

 

{hook::exec('AfterTop')}

I did exactly as instructed, at least I think I did, and still no css.  I just get plain text.  What am I doing wrong?  I created the hook in DB, added the code to the mod php file and added the new hook to header.tpl with the code provided.  Am I missing something?  

Link to comment
Share on other sites

I did exactly as instructed, at least I think I did, and still no css.  I just get plain text.  What am I doing wrong?  I created the hook in DB, added the code to the mod php file and added the new hook to header.tpl with the code provided.  Am I missing something?  

Nevermind I fixed it by following Vekia's excellent tutorial:

 

how to move block top menu module to top section

 
Thanks for all you do Vekia
Link to comment
Share on other sites

I used the linked guide to add the style but I cannot get it work.

 

I added a new hook {hook::exec('AfterTop')} right before </header>
 
I already added this to my blocktopmenu.php file:
public function hookAfterTop($params){
return $this->hookDisplayTop($params);
}

So I add there the code of the coolpapes guide, now i have this:

public function hookAfterTop($params){
public function hookAfterTop($params){
$this->context->controller->addJS($this->_path.'js/hoverIntent.js');
$this->context->controller->addJS($this->_path.'js/superfish-modified.js');
$this->context->controller->addJS($this->_path.'js/blocktopmenu.js');
$this->context->controller->addCSS($this->_path.'css/blocktopmenu.css');
$this->context->controller->addCSS($this->_path.'css/superfish-modified.css');
return $this->hookDisplayTop($params);
}

Unfortunatelly it doesn't works.

Link to comment
Share on other sites

Hello, Darkf3d3, I think we have the same problem.

With debug mod activated I found $params are not the same between new hook and hook called.

 

 

Example for me:

If I make a var_dump of hookProductFooter $params, that will return all of params.

public function hookProductChild($params){
	return $this->hookProductFooter($params);
}

If I make a var_dump of hookProductChild $params  that will return all of params except product array (The most important param for my module).


So I don't understand where is the problem...

Someone can help?
Thanks

Edited by arnaud1900 (see edit history)
Link to comment
Share on other sites

I used the linked guide to add the style but I cannot get it work.

 

I added a new hook {hook::exec('AfterTop')} right before </header>
 
I already added this to my blocktopmenu.php file:
public function hookAfterTop($params){
return $this->hookDisplayTop($params);
}

So I add there the code of the coolpapes guide, now i have this:

public function hookAfterTop($params){
public function hookAfterTop($params){
$this->context->controller->addJS($this->_path.'js/hoverIntent.js');
$this->context->controller->addJS($this->_path.'js/superfish-modified.js');
$this->context->controller->addJS($this->_path.'js/blocktopmenu.js');
$this->context->controller->addCSS($this->_path.'css/blocktopmenu.css');
$this->context->controller->addCSS($this->_path.'css/superfish-modified.css');
return $this->hookDisplayTop($params);
}

Unfortunatelly it doesn't works.

 

prestashop 1.6 moves all js and css files to footer section

make sure that your files arent moved there.

Link to comment
Share on other sites

Finally I solved it with other method.

public function hookChildProduct($params){
        //get the Object missing
	$productVars = new Product((int)$params['id_product']);

        //transform to array
	$arrayProductVars = array();
        //needed for an other function
	$arrayProductVars['product'] = $productVars;
	return $this->hookProductFooter($arrayProductVars);
}

It's working, but I always don't understood what was the difference between two $params.

Link to comment
Share on other sites

prestashop 1.4 hasn't got $this->context object

in prestashop 1.4 you have to use Tools::AddCss and Tools::AddJs instead of funciton in context object

 

also it's worth to mention that ps 1.4 hasn't got displayTop hook, just top

 

so you have to use public $this->hookTop($params) instead of $this->hookDisplayTop($params)

Link to comment
Share on other sites

prestashop 1.6 moves all js and css files to footer section

make sure that your files arent moved there.

 

Hi vekia, do you have the possibility to test the passage of your guide, but instead of using an existing hook with a new one placed right before the closing head tag?

Like mine:

	{hook::exec('AfterTop')}
	</header>
Link to comment
Share on other sites

 

Hi vekia, do you have the possibility to test the passage of your guide, but instead of using an existing hook with a new one placed right before the closing head tag?

Like mine:

	{hook::exec('AfterTop')}
	</header>

To summarize this is what I did:

 

I created a new hook in the DB named "AfterTop"

 

I added the following code to blocktopmenu.php just befor the closing bracket:

        public function hookAfterTop($params){
		return $this->hookDisplayTop($params);
	}
	
        public function hookdisplayHeader($params){
		$this->context->controller->addJS($this->_path.'js/hoverIntent.js');
		$this->context->controller->addJS($this->_path.'js/superfish-modified.js');
		$this->context->controller->addJS($this->_path.'js/blocktopmenu.js');
		$this->context->controller->addCSS($this->_path.'css/blocktopmenu.css');
		$this->context->controller->addCSS($this->_path.'css/superfish-modified.css');
	}

Then I added this hook in header.tpl:

      {hook::exec('AfterTop')}
   </div>
</header>

Then I selected the Top Menu module in the BO and clicked on configure and then save to recompile it. That moved the menu to the bottom of the header, after the container div so I could make it full width. 

 

I hope this helps clarify things

Edited by coolpapes (see edit history)
  • Like 1
Link to comment
Share on other sites

Ok, I do exaclty like your post but no style on blocktopmenu. I start thinking that maybe I made a mistake whit module position.

Actually from BO i have the block top menu module attached to: "AfterTop" and "actionCategoryUpdate". It's the same as you?

Link to comment
Share on other sites

Ok, I do exaclty like your post but no style on blocktopmenu. I start thinking that maybe I made a mistake whit module position.

Actually from BO i have the block top menu module attached to: "AfterTop" and "actionCategoryUpdate". It's the same as you?

I also have it hooked to displayHeader as well as the action hooks and AfterTop

Link to comment
Share on other sites

×
×
  • Create New...