<?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; price drop</title>
	<atom:link href="http://nemops.com/tag/price-drop/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 show more products in the Prestashop Specials module</title>
		<link>http://nemops.com/product-list-prestashop-specials-module/</link>
		<comments>http://nemops.com/product-list-prestashop-specials-module/#comments</comments>
		<pubDate>Thu, 21 Nov 2013 10:12:02 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[price drop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=1685</guid>
		<description><![CDATA[<p>In today&#8217;s tutorial we will see how to display more discounted products in the Prestashop Specials Block module, by using a native function the software already provides. Version used: Prestashop 1.5.6 Introduction Today will make use of the native getPricesDrop method the Product class kindly provides, to display as many discounted products we want in [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/product-list-prestashop-specials-module/">How to show more products in the Prestashop Specials module</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In today&#8217;s tutorial we will see how to display more discounted products in the Prestashop Specials Block module, by using a native function the software already provides.</p>
<p><span id="more-1685"></span></p>
<a class="download-files button style1" href="http://nemops.com/wp-content/uploads/2013/11/more_prices_drop.zip" title="Download Project Files">Download Project Files</a>
<ul>
<li>
		Version used: <strong>Prestashop 1.5.6</strong>
	</li>
</ul>
<h2>Introduction</h2>
<p>Today will make use of the native <strong>getPricesDrop</strong> method the Product class kindly provides, to display as many discounted products we want in the sidebar block.</p>
<p>Note that unlike previous tutorials, we will now directly edit core files, so that even the beginner user can tag along without having to know how to create a module from scratch, or how to use overrides. Therefore, please note that the changes we are going to apply <strong>will be gone</strong> if you upgrade Prestashop. If you want to do it, be sure you keep <strong>a copy of the blockspecials folder</strong>, so that you can always paste it over the original one, once the upgrade is complete. Of course, there is a slight chance you will see small bugs pop out in this case.</p>
<div class="separator"></div>
<h2>The &#8216;cache&#8217; problem and the default theme&#8217;s override</h2>
<p>There are 2 preliminary things to mention: firstly, the <strong>Specials Block Module</strong> (named blockspecials) is cached. This means that our changes will not be reflected unless we clear smarty cache upon modifying it; secondly, if you use the default theme, the blockspecials module has a template file in the theme&#8217;s folder, which is the one we need to edit.</p>
<p>Now that we know this, let&#8217;s get started!</p>
<div class="separator"></div>
<h2>Modifying the Specials Block Module class</h2>
<p>Reach out <em>modules/blockspecials/</em> and open up <strong>blockspecials.php</strong>. Now locate the <strong>hookRightColumn method, which looks approximately like this (mine is taken from 1.5.6)</strong>:</p>
<pre class="brush: php; title: ; notranslate">

	public function hookRightColumn($params)
	{
		if (Configuration::get('PS_CATALOG_MODE'))
			return;
		
		// We need to create multiple caches because the products are sorted randomly
		$random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1)));

		if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this-&gt;isCached('blockspecials.tpl', $this-&gt;getCacheId('blockspecials|'.$random)))
		{
			if (!($special = Product::getRandomSpecial((int)$params['cookie']-&gt;id_lang)) &amp;&amp; !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
				return;

			$this-&gt;smarty-&gt;assign(array(
				'special' =&gt; $special,
				'priceWithoutReduction_tax_excl' =&gt; Tools::ps_round($special['price_without_reduction'], 2),
				'mediumSize' =&gt; Image::getSize(ImageType::getFormatedName('medium')),
			));
		}

		return $this-&gt;display(__FILE__, 'blockspecials.tpl', $this-&gt;getCacheId('blockspecials|'.$random));
	}

</pre>
<p>Now, look closely at the following snippet</p>
<pre class="brush: php; title: ; notranslate">
	$special = Product::getRandomSpecial((int)$params['cookie']-&gt;id_lang)
</pre>
<p>This is the code that grabs a single random discounted product. We need to replace this with another method, which instead grabs <strong>a list of discounted products</strong>.</p>
<p>Therefore, change the snippet into this:</p>
<pre class="brush: php; title: ; notranslate">
	$specials = Product::getPricesDrop((int)$params['cookie']-&gt;id_lang, 0, 5)
</pre>
<p><strong>Explanation:</strong> as mentioned at the beginning of the article, we are making use of the built-in function Prestashop already provides with the Product Class: <strong>getPricesDrop</strong>. This is called on the &#8216;price-drop&#8217; page, and allows you to retrieve a list of all the currently active specials, with pagination. As we don&#8217;t need pagination, we use the second parameter to tell the method that we want to display page 0, and to grab 5 elements. Of course, feel free to grab as many as you want, by changing the last parameter.</p>
<p>At this point, as we also changed the variable name to <strong>specials</strong> to be more descriptive, we need to amend the following part as well:</p>
<pre class="brush: php; title: ; notranslate">

		$this-&gt;smarty-&gt;assign(array(
			'special' =&gt; $special,
			'priceWithoutReduction_tax_excl' =&gt; Tools::ps_round($special['price_without_reduction'], 2),
			'mediumSize' =&gt; Image::getSize(ImageType::getFormatedName('medium')),
		));


</pre>
<p>So change special into specials, and get rid of the second element in the array, as it&#8217;s referring to a single product price</p>
<pre class="brush: php; title: ; notranslate">

		$this-&gt;smarty-&gt;assign(array(
			'specials' =&gt; $specials,
			'mediumSize' =&gt; Image::getSize(ImageType::getFormatedName('medium')),
		));


</pre>
<p>At this point, the hookRightColumn method should look like this:</p>
<pre class="brush: php; title: ; notranslate">
	public function hookRightColumn($params)
	{
		if (Configuration::get('PS_CATALOG_MODE'))
			return;
		
		// We need to create multiple caches because the products are sorted randomly
		$random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1)));

		if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this-&gt;isCached('blockspecials.tpl', $this-&gt;getCacheId('blockspecials|'.$random)))
		{
			if (!($specials = Product::getPricesDrop((int)$params['cookie']-&gt;id_lang, 0, 5)) &amp;&amp; !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
				return;

			$this-&gt;smarty-&gt;assign(array(
				'specials' =&gt; $specials,
				'mediumSize' =&gt; Image::getSize(ImageType::getFormatedName('medium')),
			));

		}

		return $this-&gt;display(__FILE__, 'blockspecials.tpl', $this-&gt;getCacheId('blockspecials|'.$random));
	}
</pre>
<p>Now login to the back office, go to <strong>Advanced Parameters, Performance</strong> and hit the &#8216;Clear Smarty cache &#038; Autoload cache&#8217; button. <strong>Note</strong> that this button is not present if your Prestashop version is lower than 1.5.5. If this is the case, go to the <em>cache/smarty/cache</em> folder and delete <strong>blockspecials</strong>. If the folder is not there, delete everything but index.php.</p>
<p>Also, if your Prestashop version is quite old, you might need to go to <em>tools/smarty/</em> to find the cache folder/</p>
<div class="separator"></div>
<h2>Editing the Specials Module Template</h2>
<p>Okay, we have our discounted products list. However, if we now load the front page while the module is activated, we will receive an error, as it&#8217;s still referring to the old variable:</p>
<p><img src="http://nemops.com/wp-content/uploads/2013/11/error.png" alt="How to show more discounted products in blockspecials - error" width="657" height="568" class="alignnone size-full wp-image-1687" /></p>
<p>Let&#8217;s take care of it. As mentioned at the beginning of the article, if you use the default theme you can reach <em>themes/default/modules/blockspecials</em> and edit <strong>blockspecials.tpl</strong> from there. If you don&#8217;t, check the presence of that file in your theme folder, and if it&#8217;s absent, open the original <strong>blockspecials.tpl</strong> found in the module folder (the same folder where we modified the .php file).</p>
<p>It should look approximately like this (again, Prestashop 1.5.6 here!):</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA &lt;contact@prestashop.com&gt;
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark &amp; Property of PrestaShop SA
*}

&lt;!-- MODULE Block specials --&gt;
&lt;div id=&quot;special_block_right&quot; class=&quot;block products_block exclusive blockspecials&quot;&gt;
	&lt;p class=&quot;title_block&quot;&gt;&lt;a href=&quot;{$link-&gt;getPageLink('prices-drop')|escape:'html'}&quot; title=&quot;{l s='Specials' mod='blockspecials'}&quot;&gt;{l s='Specials' mod='blockspecials'}&lt;/a&gt;&lt;/p&gt;
	&lt;div class=&quot;block_content&quot;&gt;

{if $special}
		&lt;ul class=&quot;products clearfix&quot;&gt;
			&lt;li class=&quot;product_image&quot;&gt;
				&lt;a href=&quot;{$special.link|escape:'html'}&quot;&gt;&lt;img src=&quot;{$link-&gt;getImageLink($special.link_rewrite, $special.id_image, 'medium_default')|escape:'html'}&quot; alt=&quot;{$special.legend|escape:html:'UTF-8'}&quot; height=&quot;{$mediumSize.height}&quot; width=&quot;{$mediumSize.width}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot; /&gt;&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				{if !$PS_CATALOG_MODE}
					{if $special.specific_prices}
						{assign var='specific_prices' value=$special.specific_prices}
						{if $specific_prices.reduction_type == 'percentage' &amp;&amp; ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' &lt;= $specific_prices.to &amp;&amp; $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' &gt;= $specific_prices.from))}
							&lt;span class=&quot;reduction&quot;&gt;&lt;span&gt;-{$specific_prices.reduction*100|floatval}%&lt;/span&gt;&lt;/span&gt;
						{/if}
					{/if}
				{/if}

					&lt;p class=&quot;s_title_block&quot;&gt;&lt;a href=&quot;{$special.link|escape:'html'}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot;&gt;{$special.name|escape:html:'UTF-8'}&lt;/a&gt;&lt;/p&gt;
				{if !$PS_CATALOG_MODE}
					&lt;span class=&quot;price-discount&quot;&gt;{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}&lt;/span&gt;
					&lt;span class=&quot;price&quot;&gt;{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}&lt;/span&gt;
				{/if}
			&lt;/li&gt;
		&lt;/ul&gt;
		&lt;p&gt;
			&lt;a href=&quot;{$link-&gt;getPageLink('prices-drop')|escape:'html'}&quot; title=&quot;{l s='All specials' mod='blockspecials'}&quot;&gt;&amp;raquo; {l s='All specials' mod='blockspecials'}&lt;/a&gt;
		&lt;/p&gt;
{else}
		&lt;p&gt;{l s='No specials at this time' mod='blockspecials'}&lt;/p&gt;
{/if}
	&lt;/div&gt;
&lt;/div&gt;
&lt;!-- /MODULE Block specials --&gt;
</pre>
<p>The modification we need to apply can be done in a single step:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA &lt;contact@prestashop.com&gt;
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark &amp; Property of PrestaShop SA
*}

&lt;!-- MODULE Block specials --&gt;
&lt;div id=&quot;special_block_right&quot; class=&quot;block products_block exclusive blockspecials&quot;&gt;
	&lt;p class=&quot;title_block&quot;&gt;&lt;a href=&quot;{$link-&gt;getPageLink('prices-drop')|escape:'html'}&quot; title=&quot;{l s='Specials' mod='blockspecials'}&quot;&gt;{l s='Specials' mod='blockspecials'}&lt;/a&gt;&lt;/p&gt;
	&lt;div class=&quot;block_content&quot;&gt;

{if $specials}
		&lt;ul class=&quot;products clearfix&quot;&gt;
			{foreach from=$specials item=special}
				&lt;li&gt;
					&lt;a href=&quot;{$special.link|escape:'html'}&quot;&gt;&lt;img src=&quot;{$link-&gt;getImageLink($special.link_rewrite, $special.id_image, 'medium_default')|escape:'html'}&quot; alt=&quot;{$special.legend|escape:html:'UTF-8'}&quot; height=&quot;{$mediumSize.height}&quot; width=&quot;{$mediumSize.width}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot; /&gt;&lt;/a&gt;

					{if !$PS_CATALOG_MODE}
						{if $special.specific_prices}
							{assign var='specific_prices' value=$special.specific_prices}
							{if $specific_prices.reduction_type == 'percentage' &amp;&amp; ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' &lt;= $specific_prices.to &amp;&amp; $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' &gt;= $specific_prices.from))}
								&lt;span class=&quot;reduction&quot;&gt;&lt;span&gt;-{$specific_prices.reduction*100|floatval}%&lt;/span&gt;&lt;/span&gt;
							{/if}
						{/if}
					{/if}

						&lt;p class=&quot;s_title_block&quot;&gt;&lt;a href=&quot;{$special.link|escape:'html'}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot;&gt;{$special.name|escape:html:'UTF-8'}&lt;/a&gt;&lt;/p&gt;
					{if !$PS_CATALOG_MODE}
						&lt;span class=&quot;price-discount&quot;&gt;{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}&lt;/span&gt;
						&lt;span class=&quot;price&quot;&gt;{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}&lt;/span&gt;
					{/if}
				&lt;/li&gt;
			{/foreach}
		&lt;/ul&gt;
		&lt;p&gt;
			&lt;a href=&quot;{$link-&gt;getPageLink('prices-drop')|escape:'html'}&quot; title=&quot;{l s='All specials' mod='blockspecials'}&quot;&gt;&amp;raquo; {l s='All specials' mod='blockspecials'}&lt;/a&gt;
		&lt;/p&gt;
{else}
		&lt;p&gt;{l s='No specials at this time' mod='blockspecials'}&lt;/p&gt;
{/if}
	&lt;/div&gt;
&lt;/div&gt;
&lt;!-- /MODULE Block specials --&gt;

</pre>
<p><strong>Explanation</strong>: first, we refer to <strong>$specials</strong>instead of $special. Then, inside the &lt;ul&gt;, we add {foreach from=$specials item=special}, and close the loop right before the closing &lt;/ul&gt;, so that everything inside will be valid for each of our special product. Then, we get rid of: </p>
<pre class="brush: php; html-script: true; title: ; notranslate">
			&lt;li class=&quot;product_image&quot;&gt;
				&lt;a href=&quot;{$special.link|escape:'html'}&quot;&gt;&lt;img src=&quot;{$link-&gt;getImageLink($special.link_rewrite, $special.id_image, 'medium_default')|escape:'html'}&quot; alt=&quot;{$special.legend|escape:html:'UTF-8'}&quot; height=&quot;{$mediumSize.height}&quot; width=&quot;{$mediumSize.width}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot; /&gt;&lt;/a&gt;
			&lt;/li&gt;
</pre>
<p>And place&#8221;</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

&lt;a class=&quot;product-img&quot; href=&quot;{$special.link|escape:'html'}&quot;&gt;&lt;img src=&quot;{$link-&gt;getImageLink($special.link_rewrite, $special.id_image, 'medium_default')|escape:'html'}&quot; alt=&quot;{$special.legend|escape:html:'UTF-8'}&quot; height=&quot;{$mediumSize.height}&quot; width=&quot;{$mediumSize.width}&quot; title=&quot;{$special.name|escape:html:'UTF-8'}&quot; /&gt;&lt;/a&gt;

</pre>
<p>At the top of the remaining <strong>li item</strong>.</p>
<p>Save and refresh, you should get something like this:</p>
<p><img src="http://nemops.com/wp-content/uploads/2013/11/specials_list.png" alt="How to show more products in the Prestashop specials block - list displayed" width="232" height="350" class="alignnone size-full wp-image-1688" /></p>
<div class="separator"></div>
<h2>Last cosmetic touches</h2>
<p>We have the list, but it looks ugly. Let&#8217;s make it at least decent! Back to the original <strong>blockspecials</strong> folder in <em>modules/</em>, open <strong>blockspecials.css</strong></p>
<p>Locate and change this:</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right li.product_image {
	padding-right:10px;
	width:62px;
}
</pre>
<p>Into this</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right li .product-img {
	float: left;
	display:block;
	margin-right:10px;
	width:62px;
}
</pre>
<p>Then adjust the list element size by changing this:</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right .products li {
	padding:15px 0;
	width: 130px;
	border:none;
}
</pre>
<p>Into this</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right .products li {
	padding:15px 0;
	width: 100%;
	border:none;
	position:relative;
	border-bottom:1px dotted #ccc;
}
</pre>
<p>Modify the reduction label from this:</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right .products span.reduction {
	display:block;
	float:right;
	padding:0 0 0 10px;
	font-weight:bold;
	font-size:12px;
	color:#fff;
	background:url(img/bg_reduction.png) no-repeat 0 0
}

</pre>
<p>To this</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right .products span.reduction {
	display:block;
	position:absolute;
	right: 0;
	bottom: 30px;
	padding:0 0 0 10px;
	font-weight:bold;
	font-size:12px;
	color:#fff;
	background:url(img/bg_reduction.png) no-repeat 0 0
}
</pre>
<p>And lastly add the following at the end of the file:</p>
<pre class="brush: css; title: ; notranslate">
#special_block_right .s_title_block, #special_block_right .price-discount, #special_block_right .price {
	float: left;
	display: block;
	width: 100px;
}
</pre>
<p>We are done!</p>
<p><img src="http://nemops.com/wp-content/uploads/2013/11/final_result.png" alt="How to show more products in the Prestashop specials block - Final Result" width="244" height="241" class="alignnone size-full wp-image-1689" /></p>
<p>The post <a rel="nofollow" href="http://nemops.com/product-list-prestashop-specials-module/">How to show more products in the Prestashop Specials module</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/product-list-prestashop-specials-module/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
