<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; hooks</title>
	<atom:link href="http://nemops.com/tag/hooks/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Hooking modules to the Category Back Office in Prestashop</title>
		<link>http://nemops.com/hook-modules-prestashop-category-back-office/</link>
		<comments>http://nemops.com/hook-modules-prestashop-category-back-office/#comments</comments>
		<pubDate>Tue, 17 May 2016 09:42:05 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[back office]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2772</guid>
		<description><![CDATA[<p>If you want to add extra fields to the category configuration page, there is no better way than using a module hooked to DisplayBackOfficeCategory. Let&#8217;s see how to implement it! Starting with a simple module First, download the project file, and place the module you will find inside the &#8220;start&#8221; folder in the modules/ folder [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/hook-modules-prestashop-category-back-office/">Hooking modules to the Category Back Office in Prestashop</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you want to add extra fields to the category configuration page, there is no better way than using a module hooked to DisplayBackOfficeCategory. Let&#8217;s see how to implement it!</p>
<p><span id="more-2772"></span></p>
<a class="download-files button style1" href="http://nemops.com/wp-content/uploads/2016/05/project.zip" title="Download Project Files">Download Project Files</a>
<h2>Starting with a simple module</h2>
<p>First, download the project file, and place the module you will find inside the &#8220;start&#8221; folder in the modules/ folder of your prestashop installation.</p>
<p>Open up displaybocategorytut.php, it&#8217;s just a very basic module structure.</p>
<pre class="brush: php; title: ; notranslate">
if (!defined('_PS_VERSION_'))
	exit;

class displayBoCategoryTut extends Module
{

	protected $_errors = array();
	protected $_html = '';


	public function __construct()
	{
		$this-&gt;name = 'displaybocategorytut';
		$this-&gt;tab = 'front_office_features';
		$this-&gt;version = '1.0';
		$this-&gt;author = 'Nemo';
		$this-&gt;need_instance = 0;
		
		$this-&gt;bootstrap = true;

	 	parent::__construct();

		$this-&gt;displayName = $this-&gt;l('Display BO Category Tutorial');
		$this-&gt;description = $this-&gt;l('Displays an additional field in the category back office');
	}
	
	public function install()
	{
		if (!parent::install())
			return false;
		return true;
	}

	public function uninstall()
	{
		if (!parent::uninstall())
			return false;
		return true;
	}

}

</pre>
<p>The first thing we need is of course some additional data we want to save and retrieve. For this reason, we need an extra method to modify the database, and add a further column to the category table:</p>
<pre class="brush: php; title: ; notranslate">
	public function alterTable($method = 'add')
	{
		if($method == 'add')
			$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'category ADD `myowninput` VARCHAR (255) NOT NULL';
		else 
			$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'category DROP COLUMN `myowninput`';

		if(!Db::getInstance()-&gt;Execute($sql))
			return false;
		return true;
	}
</pre>
<p><strong>Explanation</strong>: since we need the extra column, we are using a single method to add and remove it. We are passing in a &#8220;method&#8221; parameter, so that we can switch between actions depending on our needs.</p>
<p>As mentioned, we need this column to be added when installing, and removed when uninstalling, so let&#8217;s amend the install and uninstall methods as well:</p>
<pre class="brush: php; title: ; notranslate">


	public function install()
	{
		if (!parent::install() OR
			!$this-&gt;alterTable() OR
			!$this-&gt;registerHook('displayBackOfficeCategory') OR
			!$this-&gt;registerHook('categoryAddition') OR
			!$this-&gt;registerHook('categoryUpdate')
			)
			return false;
		return true;
	}

	public function uninstall()
	{
		if (!parent::uninstall() OR
			!$this-&gt;alterTable('remove'))
			return false;
		return true;
	}

</pre>
<p>Additionally, I am registering two hooks to update the field&#8217;s value. This would not be necessary if we had a Category class override to take care of the extra field (see more on <a href="http://nemops.com/extending-prestashop-objects/" title="Extending PrestaShop Objects">Extending PrestaShop Objects</a>).</p>
<p>Next, we will need some way to retrieve our custom field from the database</p>
<pre class="brush: php; title: ; notranslate">
	public function getMyOwnInput($id_category)
	{
		return Db::getInstance()-&gt;getValue('SELECT myowninput FROM '._DB_PREFIX_.'category WHERE id_category = '. (int)$id_category);
	}
</pre>
<p>Then, it&#8217;s time to display something in the category back office. Let&#8217;s create the hooking method:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayBackOfficeCategory($params)
	{

		// we need an actual id, otherwise if we are just adding the category this field can be left empty
		if(Tools::getValue('id_category'))
			$myowninput = $this-&gt;getMyOwnInput(Tools::getValue('id_category'));
		else $myowninput = '';

		$this-&gt;context-&gt;smarty-&gt;assign(array(
			'myowninput'=&gt; $myowninput
		));


		return $this-&gt;display(__FILE__, 'backoffice.tpl');
	}

</pre>
<p><strong>Explanation:</strong> First off, we make sure we have a category ID that we can use to retrieve the value from the database. We use a switch to prevent the script from causing trouble in case there is none (that is, we are just creating a new category). Then, we assign the input value to the template, and return it. We don&#8217;t have it yet, so let&#8217;s create a new file inside <em>views\templates\hook</em>, naming it <strong>backoffice.tpl</strong></p>
<p>Let&#8217;s add some simple markup:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
&lt;div class=&quot;form-group&quot;&gt;
	&lt;label class=&quot;control-label col-lg-3&quot;&gt;
		&lt;span class=&quot;label-tooltip&quot;&gt;
			{l s='Custom Input' mod='displaybocategorytut'}
		&lt;/span&gt;
	&lt;/label&gt;
	&lt;div class=&quot;col-lg-4&quot;&gt;
		&lt;input type=&quot;text&quot; name=&quot;myowninput&quot; value=&quot;{$myowninput}&quot;&gt;
	&lt;/div&gt;
	&lt;div class=&quot;col-lg-6 col-lg-offset-3&quot;&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>We are ready to install the module! Go ahead and do it from the modules page. If everything goes smoothly as it should, reach a category and click edit (or add one). It should display our new field:</p>
<p><a href="http://nemops.com/wp-content/uploads/2016/05/displaybocategory.png"><img src="http://nemops.com/wp-content/uploads/2016/05/displaybocategory-680x247.png" alt="New input in the PrestaShop Category Back Office " width="680" height="247" class="aligncenter size-large wp-image-2776" /></a></p>
<p>It won&#8217;t do much at the time being, since we are not saving the value on submit. For this, we need another couple of methods that will take advantage of the hooks we registered upon install:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookCategoryAddition($params)
	{
		Db::getInstance()-&gt;update('category', array('myowninput' =&gt; pSQL(Tools::getValue('myowninput'))), 'id_category = ' . $params['category']-&gt;id);
	}

	public function hookCategoryUpdate($params)
	{
		$this-&gt;hookCategoryAddition($params);
	}
</pre>
<p><strong>Explanation:</strong> here we are using some standard code to update the database: the myowninput value is sent over via POST when submitting the page, and the $params variable passed to the method contains a useful Category object, from which we are taking the ID.</p>
<p>Now write something in the field and save, it should be stored in the database! To make sure everything runs smoothly, create a new category as well, adding content to our field before submitting the page.</p>
<p>Once everything works, you can try to expand the module with hooks, in the front office as well, and take full advantage of the new value.</p>
<h3>Additional Resources </h3>
<ul>
<li>
Learn how to develop PrestaShop Modules with my <a href="http://nemops.com/prestashop-modules-course/" title="PrestaShop Modules Course">PrestaShop Modules Course</a>
</li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/hook-modules-prestashop-category-back-office/">Hooking modules to the Category Back Office in Prestashop</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/hook-modules-prestashop-category-back-office/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add hooks to Prestashop CMS pages</title>
		<link>http://nemops.com/how-to-hooks-prestashop-cms/</link>
		<comments>http://nemops.com/how-to-hooks-prestashop-cms/#comments</comments>
		<pubDate>Wed, 20 Aug 2014 07:57:24 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2120</guid>
		<description><![CDATA[<p>Prestashop CMS pages are useful, but lack the possibility of adding modules to any of them, specifically. Let&#8217;s see how to enhance these pages and create custom hooks for them! Creating a custom hook for CMS pages The first step is to create a new, custom hook and add it to the cms.tpl file. We [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/how-to-hooks-prestashop-cms/">How to add hooks to Prestashop CMS pages</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop CMS pages are useful, but lack the possibility of adding modules to any of them, specifically. Let&#8217;s see how to enhance these pages and create custom hooks for them!</p>
<p><span id="more-2120"></span></p>
<h2>Creating a custom hook for CMS pages</h2>
<p>The first step is to create a new, custom hook and add it to the <strong>cms.tpl</strong> file. We will be using the <a href="http://nemops.com/adding-hooks-to-prestashop-1-5/#.U_MS7fna6r0" title="new way to add hooks to Prestashop">new way to add hooks</a> introduced in Prestashop 1.5.</p>
<p>Locate your <strong>cms.tpl</strong> inside the theme&#8217;s folder, and open it up in any code editor. Please notice yours might look different from mine, as I am using Prestashop 1.6.0.8</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{if isset($cms) &amp;&amp; !isset($cms_category)}
	{if !$cms-&gt;active}
		&lt;br /&gt;
		&lt;div id=&quot;admin-action-cms&quot;&gt;
			&lt;p&gt;
				&lt;span&gt;{l s='This CMS page is not visible to your customers.'}&lt;/span&gt;
				&lt;input type=&quot;hidden&quot; id=&quot;admin-action-cms-id&quot; value=&quot;{$cms-&gt;id}&quot; /&gt;
				&lt;input type=&quot;submit&quot; value=&quot;{l s='Publish'}&quot; name=&quot;publish_button&quot; class=&quot;button btn btn-default&quot;/&gt;
				&lt;input type=&quot;submit&quot; value=&quot;{l s='Back'}&quot; name=&quot;lnk_view&quot; class=&quot;button btn btn-default&quot;/&gt;
			&lt;/p&gt;
			&lt;div class=&quot;clear&quot; &gt;&lt;/div&gt;
			&lt;p id=&quot;admin-action-result&quot;&gt;&lt;/p&gt;
			&lt;/p&gt;
		&lt;/div&gt;
	{/if}
	&lt;div class=&quot;rte{if $content_only} content_only{/if}&quot;&gt;
		{$cms-&gt;content}
	&lt;/div&gt;
{elseif isset($cms_category)}
	&lt;div class=&quot;block-cms&quot;&gt;
		&lt;h1&gt;&lt;a href=&quot;{if $cms_category-&gt;id eq 1}{$base_dir}{else}{$link-&gt;getCMSCategoryLink($cms_category-&gt;id, $cms_category-&gt;link_rewrite)}{/if}&quot;&gt;{$cms_category-&gt;name|escape:'html':'UTF-8'}&lt;/a&gt;&lt;/h1&gt;
		{if $cms_category-&gt;description}
			&lt;p&gt;{$cms_category-&gt;description|escape:'html':'UTF-8'}&lt;/p&gt;
		{/if}
		{if isset($sub_category) &amp;&amp; !empty($sub_category)}	
			&lt;p class=&quot;title_block&quot;&gt;{l s='List of sub categories in %s:' sprintf=$cms_category-&gt;name}&lt;/p&gt;
			&lt;ul class=&quot;bullet list-group&quot;&gt;
				{foreach from=$sub_category item=subcategory}
					&lt;li&gt;
						&lt;a class=&quot;list-group-item&quot; href=&quot;{$link-&gt;getCMSCategoryLink($subcategory.id_cms_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}&quot;&gt;{$subcategory.name|escape:'html':'UTF-8'}&lt;/a&gt;
					&lt;/li&gt;
				{/foreach}
			&lt;/ul&gt;
		{/if}
		{if isset($cms_pages) &amp;&amp; !empty($cms_pages)}
		&lt;p class=&quot;title_block&quot;&gt;{l s='List of pages in %s:' sprintf=$cms_category-&gt;name}&lt;/p&gt;
			&lt;ul class=&quot;bullet list-group&quot;&gt;
				{foreach from=$cms_pages item=cmspages}
					&lt;li&gt;
						&lt;a class=&quot;list-group-item&quot; href=&quot;{$link-&gt;getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'html':'UTF-8'}&quot;&gt;{$cmspages.meta_title|escape:'html':'UTF-8'}&lt;/a&gt;
					&lt;/li&gt;
				{/foreach}
			&lt;/ul&gt;
		{/if}
	&lt;/div&gt;
{else}
	&lt;div class=&quot;alert alert-danger&quot;&gt;
		{l s='This page does not exist.'}
	&lt;/div&gt;
{/if}
&lt;br /&gt;
{strip}
{if isset($smarty.get.ad) &amp;&amp; $smarty.get.ad}
{addJsDefL name=ad}{$base_dir|cat:$smarty.get.ad|escape:'html':'UTF-8'}{/addJsDefL}
{/if}
{if isset($smarty.get.adtoken) &amp;&amp; $smarty.get.adtoken}
{addJsDefL name=adtoken}{$smarty.get.adtoken|escape:'html':'UTF-8'}{/addJsDefL}
{/if}
{/strip}

</pre>
<p>We first need to decide where to put our module, if before the cms content, or after it. Whichever position you choose (you might also add two hooks, one before, one after), the important section of the page is the following:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

&lt;div class=&quot;rte{if $content_only} content_only{/if}&quot;&gt;
	{$cms-&gt;content}
&lt;/div&gt;

</pre>
<p>I strongly advice to insert new hooks right outside the rte container block, to avoid cms styles to override the ones of any eventual module. At this point, let&#8217;s add the hook.</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

{hook h='customCMS'}

&lt;div class=&quot;rte{if $content_only} content_only{/if}&quot;&gt;
	{$cms-&gt;content}
&lt;/div&gt;

</pre>
<p>As you can see, I decided to add mine right before the cms content block. It is important to notice the <strong>$content_only</strong> variable. If you prefer the hook not to be executed when viewing the cms page in a lighbox, you need to wrap it inside an if statement:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

{if !$content_only} 
{hook h='customCMS'}
{/if}

&lt;div class=&quot;rte{if $content_only} content_only{/if}&quot;&gt;
	{$cms-&gt;content}
&lt;/div&gt;

</pre>
<p>This way, if you hooked something to your terms and conditions, this hook will not be executed when displaying the specific cms page in the checkout popup.</p>
<div class="separator"></div>
<h2>How to hook Modules to CMS pages</h2>
<p>We have our custom hook. It&#8217;s time to decide which module we want to plug to a cms page.</p>
<p>Given that it cannot be done without modifying core module files (and by editing a native module we are not given the chance to upgrade it without losing modifications), to make our lives easier it&#8217;s generally a good idea to simply clone/call an existing hooking method.</p>
<p>In the example, I will use the <strong>Featured Products block</strong> module, to display the featured products list in a cms page (for no reason!). Therefore, open up <strong>homefeatured.php</strong>, located at <em>modules/homefeatured</em>, and then locate the install method:</p>
<pre class="brush: php; title: ; notranslate">
	public function install()
	{
		$this-&gt;_clearCache('*');
		Configuration::updateValue('HOME_FEATURED_NBR', 8);

		if (!parent::install()
			|| !$this-&gt;registerHook('header')
			|| !$this-&gt;registerHook('addproduct')
			|| !$this-&gt;registerHook('updateproduct')
			|| !$this-&gt;registerHook('deleteproduct')
			|| !$this-&gt;registerHook('categoryUpdate')
			|| !$this-&gt;registerHook('displayHomeTab')
			|| !$this-&gt;registerHook('displayHomeTabContent')
		)
			return false;

		return true;
	}
</pre>
<p>We called our hook <strong>customCMS</strong>, so we need to register this during the module&#8217;s install:</p>
<pre class="brush: php; title: ; notranslate">
	public function install()
	{
		$this-&gt;_clearCache('*');
		Configuration::updateValue('HOME_FEATURED_NBR', 8);

		if (!parent::install()
			|| !$this-&gt;registerHook('header')
			|| !$this-&gt;registerHook('addproduct')
			|| !$this-&gt;registerHook('updateproduct')
			|| !$this-&gt;registerHook('deleteproduct')
			|| !$this-&gt;registerHook('categoryUpdate')
			|| !$this-&gt;registerHook('displayHomeTab')
			|| !$this-&gt;registerHook('displayHomeTabContent')
			|| !$this-&gt;registerHook('customCMS')
		)
			return false;

		return true;
	}
</pre>
<p>Then, we need to add the hooking method at the end of the file, before the closing bracket</p>
<pre class="brush: php; title: ; notranslate">
	public function hookcustomCMS($params)
	{
		return $this-&gt;hookDisplayHome($params);
	}
</pre>
<p>This way, we are simply calling the default method used (not in 1.6, as that&#8217;s the tab one) to show the block in the homepage. We could as well clone the same method and change it as we prefer, of course (for example if we need to use another template), but this is the quickest way.</p>
<p>Save and reset the module, then navigate to any cms page:</p>
<p><a href="http://nemops.com/wp-content/uploads/2014/08/custtom_cms_hooks.png"><img src="http://nemops.com/wp-content/uploads/2014/08/custtom_cms_hooks-663x1024.png" alt="How to add hooks to Prestashop CMS pages - Added featured products" width="663" height="1024" class="aligncenter size-large wp-image-2127" /></a></p>
<p>It&#8217;s displaying, and that&#8217;s fine. However, it&#8217;s being shown in every CMS page! How to deal with it?</p>
<div class="separator"></div>
<h2>Target specific cms page in the hooking method</h2>
<p>We obviously don&#8217;t want to display a module in every cms page, so we have to find a way to target each specific one. How? The quickest way is to use the CMS page ID, which is the number highlighted in the following screen.</p>
<p><a href="http://nemops.com/wp-content/uploads/2014/08/urls.jpg"><img src="http://nemops.com/wp-content/uploads/2014/08/urls-680x34.jpg" alt="How to add hooks to Prestashop CMS pages - CMS ID in page urls" width="680" height="34" class="aligncenter size-large wp-image-2128" /></a></p>
<p>If you use friendly urls, the ID will precede the page&#8217;s slug, like <strong>1-delivery</strong>, where 1 is the ID. If not, the id is the number following <strong>id_cms=</strong> in the url.</p>
<p>Alternatively, it&#8217;s also displayed at the far left or the table listing all available cms pages, in the back office:</p>
<p><a href="http://nemops.com/wp-content/uploads/2014/08/custom_cms_list_bo.png"><img src="http://nemops.com/wp-content/uploads/2014/08/custom_cms_list_bo-680x310.png" alt="How to add hooks to Prestashop CMS pages - CMS ID in the  back office" width="680" height="310" class="aligncenter size-large wp-image-2130" /></a></p>
<p>Once we have this information, let&#8217;s use it in our new, custom hooking method:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookcustomCMS($params)
	{

		if (Tools::getValue('id_cms') != 1)
			return;
		return $this-&gt;hookDisplayHome($params);
	}

</pre>
<p>And we are done! Try to navigate to other pages. In my case, I will only see the block if I view the Delivery Information CMS.</p>
<p>The post <a rel="nofollow" href="http://nemops.com/how-to-hooks-prestashop-cms/">How to add hooks to Prestashop CMS pages</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/how-to-hooks-prestashop-cms/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Adding hooks to Prestashop 1.5 (the new way)</title>
		<link>http://nemops.com/adding-hooks-to-prestashop-1-5/</link>
		<comments>http://nemops.com/adding-hooks-to-prestashop-1-5/#comments</comments>
		<pubDate>Mon, 11 Feb 2013 11:01:20 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[prestashop 1.5]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=1007</guid>
		<description><![CDATA[<p>Prestashop 1.5 introduced a new way to add hooks, which doesn&#8217;t involve overrides or database queries. Unfortunately, it&#8217;s not yet been documented in the offiacial Docs, so let&#8217;s see how to take advantage of it! Watch the screencast &#160; Text version The old VS the new hooks syntax If you were used to adding hooks [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/adding-hooks-to-prestashop-1-5/">Quick Tip: Adding hooks to Prestashop 1.5 (the new way)</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop 1.5 introduced a new way to add hooks, which doesn&#8217;t involve overrides or database queries. Unfortunately, it&#8217;s not yet been documented in the offiacial Docs, so let&#8217;s see how to take advantage of it!</p>
<p><span id="more-1007"></span></p>
<h2>Watch the screencast</h2>

	<div class="video-embed">
		<iframe width="640" height="360" src="http://www.youtube.com/embed/E5F5Bqr7YMI" frameborder="0" allowfullscreen></iframe><p><a href="https://www.youtube.com/user/NemoPostScriptum/videos" rel="nofollow" title="Subscribe Post Scriptum's Youtube Channel">Subscribe Post Scriptum's Youtube Channel</a></p>	</div>
<div class="separator"></div>
<h2>Text version</h2>
<h3>The old VS the new hooks syntax</h3>
<p>If you were used to adding  <a href="http://nemops.com/a-deeper-look-at-prestashop-hooks/" title="Prestashop Hooks tutorial">hooks to Prestashop 1.4</a>, you might remember having to write something like this</p>
<pre class="brush:php">
INSERT INTO `ps_hook` (`name`, `title`, `description`) 
VALUES ('category', 'Category', 'Hooks before the product list in a category');	
</pre>
<p>Into your database to add the hook, and then override one of the controllers to register its execution, like this:</p>
<pre class="brush:php">
Class FrontController extends FrontControllerCore
{
 
    public function displayHeader()
    {
        if (!self::$initialized)
             $this->init();
 
            self::$smarty->assign('HOOK_CATEGORY', Module::hookExec('category'));
 
        parent::displayHeader();        
    }
 
}
</pre>
<p>And this was SO bad, forcing us to use overrides for almost every place which didn&#8217;t have its own hook already.</p>
<p>Luckily, but &#8220;secretly&#8221; for some reason, a new and simpler way has been introduced, and that is, substantially, adding this to a template file:</p>
<pre class="brush:php">
	{hook h='nameOfTheHook'}
</pre>
<p>I discovered it by chance actually, scrabbing throughout the forums, from a post of one the Prestashop Core&#8217;s developers: Fabien Serny (<a href="http://www.prestashop.com/forums/topic/173027-solved-how-to-create-a-new-hook-in-15-am-i-doing-it-wrong/page__st__20" title="Original post on the new hook syntax in prestashop 1.5">reference</a>)</p>
<div class="separator">&nbsp;</div>
<h3>Example: adding a new hook for the first time</h3>
<p>For the sake of this example, we&#8217;ll just be writing some piece of text above the footer. Therefore, open up <em>themes/default/footer.tpl</em>, and right before {$HOOK_FOOTER}, add the following</p>
<pre class="brush:php">
	{hook h='beforeFooter'}	
</pre>
<p>The name is, of course, discretional. Nothing else has to be done actually, but registering the hook as any other existent hook. Open up any module you have installed, for example <strong>blocknewsletter.php</strong>. I&#8217;ll be using this for demonstrational purposes only, you can use any. At the end of the file, add a simple hooking function:</p>
<pre class="brush:php">	
public function hookBeforeFooter($params)
{
	return 'hi there!';
}
</pre>
<p>The function is now there, but this module is not registered as being part of this hook. We won&#8217;t be able to position it to the new hook from the back office yet. <strong>The first time you create the hook, it has to be registered at least once, from a module</strong>. We can use a regular registerHook for this, as any other hook. In the install() function of the module, add the registration, so it looks like this:</p>
<pre class="brush:php">
	if (parent::install() == false || $this->registerHook('leftColumn') == false ||  $this->registerHook('beforeFooter') == false || $this->registerHook('header') == false)
		return false;	
</pre>
<p>Again, this is just an example, the important part is the following one (it will look familiar if you know how to create modules and register hooks; if it doesn&#8217;t, have a look at my previous tutorial about <a href="http://nemops.com/a-deeper-look-at-prestashop-hooks/" title="Prestashop Hooks tutorial">Prestashop Hooks</a>, as the basic ideas are still valid):</p>
<pre class="brush:php">
	$this->registerHook('beforeFooter')
</pre>
<p>Go back to the modules panel and reset the module (or install it, if it wasn&#8217;t). Refresh the front office, and you&#8217;ll see the &#8220;Hi there!&#8221; text appear where it&#8217;s supposed to be.</p>
<p>Isn&#8217;t this a HUGE improvement? Yay, it is. But if you still use Prestashop 1.4, you can go the old way with my module <a href="http://store.nemops.com/17-ez-hook.html">EZ Hooks</a>, and create new hooks in 1 click.</p>
<p>The post <a rel="nofollow" href="http://nemops.com/adding-hooks-to-prestashop-1-5/">Quick Tip: Adding hooks to Prestashop 1.5 (the new way)</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/adding-hooks-to-prestashop-1-5/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
