<?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; override</title>
	<atom:link href="http://nemops.com/tag/override/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>How to (finally) override Prestashop Modules&#8217; core files</title>
		<link>http://nemops.com/override-prestashop-modules-core/</link>
		<comments>http://nemops.com/override-prestashop-modules-core/#comments</comments>
		<pubDate>Mon, 19 Jan 2015 10:39:10 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[core]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2290</guid>
		<description><![CDATA[<p>Without even letting us know, the Prestashop team finally made it possible to override Prestashop Modules&#8217; core files in version 1.6.0.11. Let&#8217;s see how! Prestashop version: 1.6.0.11 and above How to (finally) override Prestashop Modules&#8217; core files Yes, we (at last!) can now override modules&#8217; php files without messing with the core itself. It seems [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/override-prestashop-modules-core/">How to (finally) override Prestashop Modules&#8217; core files</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Without even letting us know, the Prestashop team finally made it possible to override Prestashop Modules&#8217; core files in version 1.6.0.11. Let&#8217;s see how!</p>
<p><span id="more-2290"></span></p>
<ul>
<li>Prestashop version: <strong>1.6.0.11 and above</strong></li>
</ul>
<h2>How to (finally) override Prestashop Modules&#8217; core files</h2>
<p>Yes, we (at last!) can now override modules&#8217; php files without messing with the core itself. It seems this mod has been around for a few days now, and the prestashop team, of course, didn&#8217;t let anyone now. I&#8217;d like to thank the Prestashop forum user <strong>Razaro</strong> who spotted this first.</p>
<p>Enough chitchatting. Let&#8217;s see how to override a Prestashop Module&#8217;s core. Reach the new <em>override/modules/</em> folder. For this demonstration we will override the cms block, just to illustrate the purpose. Create a new folder called <strong>blockcms</strong>, and inside it a file named <strong>blockcms.php</strong>. Here is how modules overrides work:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

if (!defined('_CAN_LOAD_FILES_'))
	exit;

class BlockCmsOverride extends BlockCms
{


}

</pre>
<p>The pattern is ModuleName<strong>Override</strong>. So in this case BlockCmsOverride. If we wanted to extend the top menu, it would have been BlockTopMenuOverride, and so on. Pretty easy to remember. Now let&#8217;s go ahead and simply add a var dump to make sure it works:</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php


if (!defined('_CAN_LOAD_FILES_'))
	exit;

class BlockCmsOverride extends BlockCms
{
	public function displayBlockCMS($column)
	{
		var_dump('testing');
		if (!$this-&gt;isCached('blockcms.tpl', $this-&gt;getCacheId($column)))
		{
			$cms_titles = BlockCMSModel::getCMSTitles($column);

			$this-&gt;smarty-&gt;assign(array(
				'block' =&gt; 1,
				'cms_titles' =&gt; $cms_titles,
				'contact_url' =&gt; (_PS_VERSION_ &gt;= 1.5) ? 'contact' : 'contact-form'
			));
		}
		return $this-&gt;display(__FILE__, 'blockcms.tpl', $this-&gt;getCacheId($column));
	}

}


</pre>
<p>Nothing fancy, it doesn&#8217;t do anything but it&#8217;s great to understand how the thing works: as with all overrides, you just have to replicate a method&#8217;s name to extend or replace it. We can also call the parent if we want, and make things more concise:</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php


if (!defined('_CAN_LOAD_FILES_'))
	exit;

class BlockCmsOverride extends BlockCms
{
	public function displayBlockCMS($column)
	{
		var_dump('testing');
		parent::displayBlockCMS($column);
	}

}


</pre>
<p>As simple as that! Think about the possibilities, and <strong>the flexibility this gives to theme developers</strong>. Of course make sure you clear the class_index./php file located in the <em>cache/</em> folder before testing it out!</p>
<p>And of course, like normal overrides, we can just create the very same &#8220;blockcms&#8221; folder in our third party module, so it will be automatically added when installed, again, like classes and controllers overrides.</p>
<div class="separator"></div>
<h2>Last mention</h2>
<p>Since this silence towards the community is getting pretty annoying, I hope the Prestashop team will soon try to have more consideration for the user and developers base, informing us when such a new feature is released. Just a small code snippet for them: </p>
<pre class="brush: php; title: ; notranslate">
if($prestashop - $community)
	die();
</pre>
<p><img src="http://nemops.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>The post <a rel="nofollow" href="http://nemops.com/override-prestashop-modules-core/">How to (finally) override Prestashop Modules&#8217; core files</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/override-prestashop-modules-core/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Prestashop: Upgrade-safe template modifications</title>
		<link>http://nemops.com/prestashop-upgrade-safe-template-modifications/</link>
		<comments>http://nemops.com/prestashop-upgrade-safe-template-modifications/#comments</comments>
		<pubDate>Wed, 03 Dec 2014 09:10:33 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Theming]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2227</guid>
		<description><![CDATA[<p>If you have ever been frustrated because your template modifications got lost after upgrading, here is the final, bulletproof solution for upgrade-safe prestashop template modifications (with overrides!). Last week, I came across a really useful hook, almost by chance: displayOverrideTemplate. It&#8217;s not (of course) mentioned anywhere in the official Prestashop documentation, but it&#8217;s fundamental to [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-upgrade-safe-template-modifications/">Prestashop: Upgrade-safe template modifications</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you have ever been frustrated because your template modifications got lost after upgrading, here is the final, bulletproof solution for upgrade-safe prestashop template modifications (with overrides!).</p>
<p><span id="more-2227"></span></p>
<a class="download-files button style1" href="http://nemops.com/wp-content/uploads/2014/12/psoverridetemplatedemo.zip" title="Download Project Files">Download Project Files</a>
<p>Last week, I came across a really useful hook, almost by chance: <strong>displayOverrideTemplate</strong>. It&#8217;s not (of course) mentioned anywhere in the official Prestashop documentation, but it&#8217;s fundamental to anyone willing to extend/modify the current template without fearing to lose all these tweaks with the next upgrade.</p>
<p>It&#8217;s been around since Prestashop 1.5, given what the calling method states, inside the <strong>FrontController.php</strong> file:</p>
<pre class="brush: php; title: ; notranslate">
	/**
	 * Returns the template corresponding to the current page.
	 * By default this method return false but could easily be overridden in a specific controller
	 *
	* @since 1.5
	* @return bool
	*/
	public function getOverrideTemplate()
	{
		return Hook::exec('DisplayOverrideTemplate', array('controller' =&gt; $this));
	}
</pre>
<p>At any rate, enough chit-chatting, it&#8217;s time to see the true power of this hook!</p>
<div class="separator"></div>
<h2>Example &#8211; Overriding the category page</h2>
<p>In this example, we will use a simple module to override the category page. Download the project files above, and then place the &#8216;psoverridetemplatedemo&#8217; folder in your Prestashop <em>modules/</em> folder. It&#8217;s nothing fancy, it&#8217;s just a blank module that does absolutely nothing. We will add something to it right away: locate the install method, and register our fancy hook</p>
<pre class="brush: php; title: ; notranslate">
	public function install()
	{
		if (!parent::install() ||
			!$this-&gt;registerHook('displayOverrideTemplate')
			)
			return false;
		return true;
	}
	
</pre>
<p>Install it. Then, to test that it really works, let&#8217;s add something SO invasive:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayOverrideTemplate($params)
	{
		die('here');
		// return dirname(__FILE__).'/views/templates/hook/skeleton.tpl';
	}
</pre>
<p>This should kill every single page of your store, displaying &#8220;here&#8221; instead. If not, check the registerHook method.</p>
<p><strong>What should we now return from the hook?</strong> Not a template, as you might think, nor we will call smarty&#8217;s fetch method. <strong>We need to return a path to the template file we want to use</strong>. We have one in out module&#8217;s root (psoverridetemplatedemo.tpl), so let&#8217;s reference it here:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayOverrideTemplate($params)
	{
		return dirname(__FILE__).'/psoverridetemplatedemo.tpl';
	}
</pre>
<p>Save and refresh. Every page of your store should now have the center column blank. Why? Because there is nothing in the template file. Add some garbage test to try it out, and you will see it appearing in every page. Yes, but this is not so useful, <strong>how can we replace a specific template?</strong> In a previous tutorial on <a href="http://nemops.com/page-specific-prestashop-module/#.VHeY7jGjOr0" target="_blank" title="Target specific pages from a Prestashop Module’s Hook">Target specific pages from a Prestashop Module’s Hook</a>, I showed you how to get each page&#8217;s specific identifier using the following method:</p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;context-&gt;controller-&gt;php_self
</pre>
<p>If you recall the beginning of this article, we saw the Front Controller is passing the current controller object into the hook, which is then available to us for use within our method. The snippet I just mentioned therefore becomes:</p>
<pre class="brush: php; title: ; notranslate">
$params['controller']-&gt;php_self;
</pre>
<p>Easy as that. Let&#8217;s override the category page only, for example:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayOverrideTemplate($params)
	{
		if ($params['controller']-&gt;php_self == 'category')
			return dirname(__FILE__).'/psoverridetemplatedemo.tpl';
	}
</pre>
<p>Save and refresh. The only overridden template will now be the category one! Sounds like a good deal. What about other pages? It&#8217;s easy enough to inspect each page&#8217;s name as follows:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayOverrideTemplate($params)
	{
		var_dump($params['controller']-&gt;php_self);
		//if ($params['controller']-&gt;php_self == 'category')
		//	return dirname(__FILE__).'/psoverridetemplatedemo.tpl';
	}
</pre>
<p>The page name will be shown at the top. <strong>There are some exceptions though.</strong></p>
<p>Some pages simply don&#8217;t have any php_self assigned, and that statement would therefore cause trouble. To overcome, it&#8217;s enough to make sure it is assigned before comparing it to anything:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookDisplayOverrideTemplate($params)
	{
		if (isset($params['controller']-&gt;php_self) &amp;&amp; $params['controller']-&gt;php_self == 'category')
			return dirname(__FILE__).'/psoverridetemplatedemo.tpl';
	}
</pre>
<p>And that&#8217;s it, you can target virtually every template for every controller with a page name now!</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-upgrade-safe-template-modifications/">Prestashop: Upgrade-safe template modifications</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-upgrade-safe-template-modifications/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
