Jump to content

[quick tutorial] how to add multiple specials to specials block


Recommended Posts

This tutorial can actually work for any block that you would like to display more than one item in the list. For this instance I wanted to display two items in the specials block instead of one.

Here is the code for my entire blockspecials.tpl - its the only file that needs changing:

<!-- MODULE Block specials -->

getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}


{if $special !== false}


       {foreach from=$special item='product' name='special'}
           {if $smarty.foreach.special.index < 2}

{$special.name|escape:html:'UTF-8'}

getImageLink($special.link_rewrite, $special.id_image, 'large')}" alt="{$special.legend|escape:html:'UTF-8'}" width="242px" title="{$special.name|escape:html:'UTF-8'}" />

            

was {if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}

               {if $special.specific_prices}
                   {assign var='specific_prices' value=$special.specific_prices}
                   {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
                       <!--(-{$specific_prices.reduction * 100|floatval}%)-->
                   {/if}
               {/if}
Now {if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}
{/if}
       {/foreach}



getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="home_button">{l s='All specials' mod='blockspecials'}

{else}

{l s='No specials at this time' mod='blockspecials'}
{/if}


<!-- /MODULE Block specials -->



A quick explanation:

The only thing that needed to be done was to create a loop so that the code knows to go back and loop up the same information twice (or as many times as you tell it to). The loop is VERY simple.

This is the start of the loop that tells it to look for the products with specials and then tells it to get 2 (you can change that number to whatever you want!!!

        {foreach from=$special item='product' name='special'}
           {if $smarty.foreach.special.index < 2}



Place the above bit of code directly before the chunk that you want to be repeated. For instance if I have an HTML structure that has is this:


PRODUCT INFO HERE
 



And you want to repeat just the product info then you will place the first chunk of code directly before the

so that it repeats the whole product info. If you wanted to repeat the entire list of products then you can place that chunk before the
and you will get that whole area repeated.

The next thing you have to do is simply close out that statement and tell it where to stop repeating. Use this:
{/if}
       {/foreach}



In the above example I would place that code directly after the

So again, the simplified version of this code is:


       {foreach from=$special item='product' name='special'}
           {if $smarty.foreach.special.index < 2}
PRODUCT INFO HERE
{/if}
       {/foreach}



ONE MORE NOTE:
You can adapt this code for just about any block you want to. You will need to replace the $special and 'special' with the variable name for that block. You can find the function name by going to that block's .php page which would be found in modules/moduleblock/moduleblock.php (replace 'moduleblock' with the actual block name)

Look for code that looks like this:

    $smarty->assign(array('special' => $special,



Where ever you see $smarty->assign you will know that the code is assigning a variable to be used throughout the templates.

So I hope this helps. Please feel free to jump in and correct me if something is wrong. I just hacked this together the best way I know how. I am not a prestashop [spam-filter] - just learning it. I do have enough experience with customizing carts to make changes like this and really like to share my stuff so that people can learn.

  • Like 2
Link to comment
Share on other sites

you need to make sure that $special contains multiple entries of products.

actually, i checked the block special module, it only get one record of special.

this is line in blocksoecial.php file that load $special data

       if ($special = Product::getRandomSpecial(intval($params['cookie']->id_lang)))




if you look into the function of getRandomSpecial() in Product class, you will see it only returns one record.

so here is solution;
you call two times the same function and set result into an array $specials, then you use the $specials at your tpl file, it should work. here is code on how to get two specials.

$specials = array();
$specials[] = Product::getRandomSpecial(intval($params['cookie']->id_lang));
$specials[] = Product::getRandomSpecial(intval($params['cookie']->id_lang));
$smarty->assign('specials',$specials);

  • Like 1
Link to comment
Share on other sites

Sorry I'm really confused by your explaination. The code you are speaking about is this correct:

    public function hookRightColumn($params)
   {
       if (Configuration::get('PS_CATALOG_MODE'))
           return ;

       global $smarty;
       if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang)) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
           return;
       $smarty->assign(array('special' => $special,
       'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'] / (1 + $special['rate'] / 100), 2),
       'mediumSize' => Image::getSize('medium')));
       return $this->display(__FILE__, 'blockspecials.tpl');
   }



I can see it is getting a random special and then displaying the results of 'special' in an array.. I do not understand how your code fits in here/

Link to comment
Share on other sites

awesome !!

partner your solution is smart but if random send 2 times the same article...

here a solution that works, not optimised, write fast but working :

in classes/product.php (u can overide this class) add a methode

public static function getRandomSpecialx($id_lang, $beginning = false, $ending = false,$nbr=1)
   {

       $currentDate = date('Y-m-d H:i:s');
       $ids_product = self::_getProductIdByDate((!$beginning ? $currentDate : $beginning), (!$ending ? $currentDate : $ending));

       $groups = FrontController::getCurrentCustomerGroups();
       $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');

       // Please keep 2 distinct queries because RAND() is an awful way to achieve this result
       $sql = '
       SELECT p.id_product
       FROM `'._DB_PREFIX_.'product` p
       WHERE 1
       AND p.`active` = 1
       AND p.`id_product` IN ('.implode(', ', $ids_product).')
       AND p.`id_product` IN (
           SELECT cp.`id_product`
           FROM `'._DB_PREFIX_.'category_group` cg
           LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
           WHERE cg.`id_group` '.$sqlGroups.'
       )
       ORDER BY RAND() limit 0,'.$nbr;
       $id_products = Db::getInstance()->ExecuteS($sql);

       if (count($id_products) == 0)
           return false;

       $row = array();    
       $i = 0;

       foreach ($id_products as $id_product)
       {
           $row[$i] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
           SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,  p.`upc`,
               i.`id_image`, il.`legend`, t.`rate`
           FROM `'._DB_PREFIX_.'product` p
           LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).')
           LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
           LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
           LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
                                                      AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
                                                         AND tr.`id_state` = 0)
           LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
           WHERE p.id_product = '.(int)$id_product[id_product]);
           $row[$i] = Product::getProductProperties($id_lang, $row[$i]);
           $i++;
       }

       return $row;
   }



in module/blockspecials/blockspecials.php

rewrite the code (or copye the prestashop module and do change on methode hookright)

public function hookRightColumn($params)
   {
       if (Configuration::get('PS_CATALOG_MODE'))
           return ;

       global $smarty;
       $special = Product::getRandomSpecialx((int)($params['cookie']->id_lang),false,false,2);
       if (count($special) == 0 AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
           return;

       $smarty->assign(array(
           'special' => $special,
           'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
           'mediumSize' => Image::getSize('medium')
       ));

       return $this->display(__FILE__, 'blockspecials.tpl');
   }



in blockspecials.tpl :

<!-- MODULE Block specials -->

getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}

{if $special|@count gt 0}

        {foreach from=$special item=item}

getImageLink($item.link_rewrite, $item.id_image, 'medium')}" alt="{$item.legend|escape:html:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$item.name|escape:html:'UTF-8'}" />


{$item.name|escape:html:'UTF-8'}
{if !$priceDisplay}{displayWtPrice p=$item.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}
               {if $item.specific_prices}
                   {assign var='specific_prices' value=$item.specific_prices}
                   {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
(-{$specific_prices.reduction*100|floatval}%)
                   {/if}
               {/if}
{if !$priceDisplay}{displayWtPrice p=$item.price}{else}{displayWtPrice p=$item.price_tax_exc}{/if}


        {/foreach}    



getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}

{else}

{l s='No specials at this time' mod='blockspecials'}
{/if}


<!-- /MODULE Block specials -->

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

@Bug00 - your code worked perfectly but had to fix a few typos. For anyone who comes across this thread in the future and gets errors that they don't know what to do with, here's the code from above with a few typos fixed:

<!-- MODULE Block specials -->

getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}

{if $special|@count gt 0}

        {foreach from=$special item=item}

{$item.name|escape:html:'UTF-8'}

getImageLink($special.link_rewrite, $item.id_image, 'large')}" alt="{$item.legend|escape:html:'UTF-8'}" height="138" width="246" title="{$item.name|escape:html:'UTF-8'}" />


{if !$priceDisplay}{displayWtPrice p=$item.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}
               {if $item.specific_prices}
                   {assign var='specific_prices' value=$item.specific_prices}
                   {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
(-{$specific_prices.reduction*100|floatval}%)
                   {/if}
               {/if}
{if !$priceDisplay}{displayWtPrice p=$item.price}{else}{displayWtPrice p=$item.price_tax_exc}{/if}


        {/foreach}    



getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}

{else}

{l s='No specials at this time' mod='blockspecials'}
{/if}


<!-- /MODULE Block specials --> 

Link to comment
Share on other sites

  • 2 weeks later...

Hi, Bug00 i tried u r code adding in my files but is giving no result, but an error text like this

 

getPageLink('prices-drop.php')}" title="Specials">Specials getImageLink($item.link_rewrite, $item.id_image, 'medium')}" alt="iPod Nano" height="80" width="80" title="iPod Nano" /> iPod Nano 187,19 Rs. (-5%) 177,83 Rs. getPageLink('prices-drop.php')}" title="All specials" class="button_large">All specials

 

the code which we have added in tpl file in my front page

 

can u pls explain me the steps and the code to be added in respective files pls again. iam using version 1.4.1 is that compatible for my version iam seeking all the images to appear in the Specials Block and using carousel for showing all the images. can u guide me.

 

Anil

Bangalore

Link to comment
Share on other sites

  • 4 weeks later...

Hello All, Iam a web developer and am designing a website for a toys store. So iam using Prestashop shopping cart version 1.4.1 iam totally new to the CMS and according to the requirements i need to display multiple specials (images) i.e more than 1 special in Specials Block i tried all u the code available in the forum but am not getting it. can any one give me a solution for achieving this please brief me all the required steps in doing this and make me complete my task please, THANKS IN ADVANCE.

Link to comment
Share on other sites

  • 2 months later...
  • 6 months later...
  • 4 months later...

awesome !!

 

partner your solution is smart but if random send 2 times the same article...

 

here a solution that works, not optimised, write fast but working :

 

in classes/product.php (u can overide this class) add a methode

 

public static function getRandomSpecialx($id_lang, $beginning = false, $ending = false,$nbr=1)
{

	$currentDate = date('Y-m-d H:i:s');
	$ids_product = self::_getProductIdByDate((!$beginning ? $currentDate : $beginning), (!$ending ? $currentDate : $ending));

	$groups = FrontController::getCurrentCustomerGroups();
	$sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');

	// Please keep 2 distinct queries because RAND() is an awful way to achieve this result
	$sql = '
	SELECT p.id_product
	FROM `'._DB_PREFIX_.'product` p
	WHERE 1
	AND p.`active` = 1
	AND p.`id_product` IN ('.implode(', ', $ids_product).')
	AND p.`id_product` IN (
		SELECT cp.`id_product`
		FROM `'._DB_PREFIX_.'category_group` cg
		LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
		WHERE cg.`id_group` '.$sqlGroups.'
	)
	ORDER BY RAND() limit 0,'.$nbr;
	$id_products = Db::getInstance()->ExecuteS($sql);

	if (count($id_products) == 0)
		return false;

	$row = array();	
	$i = 0;

	foreach ($id_products as $id_product)
	{
		$row[$i] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
		SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,  p.`upc`,
			i.`id_image`, il.`legend`, t.`rate`
		FROM `'._DB_PREFIX_.'product` p
		LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).')
		LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
		LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
												   AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
													  AND tr.`id_state` = 0)
		LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
		WHERE p.id_product = '.(int)$id_product[id_product]);
		$row[$i] = Product::getProductProperties($id_lang, $row[$i]);
		$i++;
	}

	return $row;
}

 

in module/blockspecials/blockspecials.php

 

rewrite the code (or copye the prestashop module and do change on methode hookright)

 

public function hookRightColumn($params)
{
	if (Configuration::get('PS_CATALOG_MODE'))
		return ;

	global $smarty;
	$special = Product::getRandomSpecialx((int)($params['cookie']->id_lang),false,false,2);
	if (count($special) == 0 AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
		return;

	$smarty->assign(array(
		'special' => $special,
		'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
		'mediumSize' => Image::getSize('medium')
	));

	return $this->display(__FILE__, 'blockspecials.tpl');
}

 

in blockspecials.tpl :

<!-- MODULE Block specials -->


[b]	[url=""]getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}[/url][/b]



{if $special|@count gt 0}

[list]
	 {foreach from=$special item=item}
		[*]
			[url="{$item.link}"]<img />getImageLink($item.link_rewrite, $item.id_image, 'medium')}" alt="{$item.legend|escape:html:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$item.name|escape:html:'UTF-8'}" />[/url]

		[*]				
[b]	[url="{$item.link}"]{$item.name|escape:html:'UTF-8'}[/url][/b]

			{if !$priceDisplay}{displayWtPrice p=$item.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}
			{if $item.specific_prices}
				{assign var='specific_prices' value=$item.specific_prices}
				{if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
					(-{$specific_prices.reduction*100|floatval}%)
				{/if}
			{/if}
			{if !$priceDisplay}{displayWtPrice p=$item.price}{else}{displayWtPrice p=$item.price_tax_exc}{/if}


	 {/foreach}	

[/list]		

		[url=""]getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}[/url]

{else}

{l s='No specials at this time' mod='blockspecials'}
{/if}


<!-- /MODULE Block specials -->

 

After correcting some missing bits of code from the solution above, I was able to get this to work with no duplicating of the products. However, it is only showing two special products. I see where it says to keep two distinct queries. I am assuming I would need to add more to show more special products? What do I need to edit to show more than two products? Like six products. Thanks!

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

Anyone??? After correcting some missing bits of code from the solution above, I was able to get this to work with no duplicating of the products. However, it is only showing two special products. I see where it says to keep two distinct queries. I am assuming I would need to add more to show more special products? What do I need to edit to show more than two products? Like six products. Thanks!

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hi... I am quite new to PS. I am looking for a way to check if the special (discount) of a product is due. Do you know where are the start and end date of a product´s special stored on the DB? Or how can I compare the end date with the current time for example? Thank you very much.

Link to comment
Share on other sites

  • 2 months later...

hello...

 

Now in my homefeatured i have 5 products...

 

I whant to make the pricedrop like that one under the homefeatured.

 

I have manage to do it like this:

 

<!-- MODULE Pricedrop Products -->
<div id="featured-products_block_center" class="home_products">
   <h4>{l s='Reduce rims' mod='pricedrop'}</h4>
   {if isset($special) AND $special}
   <div class="block_content">
       {assign var='liHeight' value=342}
           {assign var='nbItemsPerLine' value=4}
           {assign var='nbLi' value=$special|@count}
           {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
           {math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight}
           <ul style="height:{$ulHeight}px;">
           {foreach from=$products item=product name=pricedrop}
           <li class="ajax_block_product {if $smarty.foreach.pricedrop.first}first_item{elseif $smarty.foreach.homeFeaturedProducts.last}last_item{else}item{/if} {if $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 0}last_item_of_line{elseif $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 1}clear{/if} {if $smarty.foreach.homeFeaturedProducts.iteration > ($smarty.foreach.homeFeaturedProducts.total - ($smarty.foreach.homeFeaturedProducts.total % $nbItemsPerLine))}last_line{/if}">
               <a class="products_block_img bordercolor" href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'home')}" alt="{$special.legend|escape:html:'UTF-8'}" title="{$special.name|escape:html:'UTF-8'}" /></a><div>
               <span class="price">{if $pricedrop.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}{if !$priceDisplay}{convertPrice price=$pricedrop.price}{else}{convertPrice price=$pricedrop.price_tax_exc}{/if}{/if}</span>
               {if $special.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><span class="price">{if !$priceDisplay}{convertPrice price=$special.price}{else}{convertPrice price=$special.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}
                       <a class="button" href="{$special.link}" title="{l s='View' mod='pricedrop'}">{l s='View' mod='pricedrop'}</a>
                       {if ($special.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $special.available_for_order AND !isset($restricted_country_mode) AND $special.minimal_quantity == 1 AND $special.customizable != 2 AND !$PS_CATALOG_MODE}
                           {if ($special.quantity > 0 OR $special.allow_oosp)}
                           <a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$special.id_product}" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$special.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pricedrop'}">{l s='Add to cart' mod='pricedrop'}</a>
                           {else}
                           <span class="exclusive">{l s='Add to cart' mod='pricedrop'}</span>
                           {/if}
                       {else}
                           <div style="height:23px;"></div>
                       {/if}
               </div>
           </li>
           {/foreach}
       </ul>
   </div>
   {else}
       <p>{l s='No specials at this time' mod='pricedrop'}</p>
{/if}
</div>
<!-- MODULE Pricedrop Products -->

 

I show the 2 one that i pricedrop, but i olso show the other one that is in the home category.

Can some one help me please.....

Link to comment
Share on other sites

  • 2 months later...

my question is this..

I have prestashop_1.5.4.0 and i'm trying to make visible more than 1 product, like 4 or 6, i tried everything and search for answers i the forum but nothing worked for me, maybe because the answers are for older versions of prestashop...

 

please if you guys can help jus let me now, and sorry for my awful english..

thank you very much!!

Link to comment
Share on other sites

This is what I am using in my 1.4.7.3 store to show multiple specials (see attachment). Note that it will sometimes show the same item more than once and it lists them randomly. I have not been able to customize it any further. I also have not tried this with any newer PS versions, so I don't know if further modification would be required to make it work. Hope this helps.

 

Change the file name blockspecials.txt to blockspecials.tpl

 

For some reason, tpl files cannot be attached here.

 

 

blockspecials.php

 

blockspecials.txt

 

You can see my use of this module here... http://www.rotmgvault.com

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

  • 1 month later...

hello...

 

Now in my homefeatured i have 5 products...

 

I whant to make the pricedrop like that one under the homefeatured.

 

I have manage to do it like this:

 

<!-- MODULE Pricedrop Products -->
<div id="featured-products_block_center" class="home_products">
<h4>{l s='Reduce rims' mod='pricedrop'}</h4>
{if isset($special) AND $special}
<div class="block_content">
	{assign var='liHeight' value=342}
		{assign var='nbItemsPerLine' value=4}
		{assign var='nbLi' value=$special|@count}
		{math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}
		{math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight}
		<ul style="height:{$ulHeight}px;">
		{foreach from=$products item=product name=pricedrop}
		<li class="ajax_block_product {if $smarty.foreach.pricedrop.first}first_item{elseif $smarty.foreach.homeFeaturedProducts.last}last_item{else}item{/if} {if $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 0}last_item_of_line{elseif $smarty.foreach.homeFeaturedProducts.iteration%$nbItemsPerLine == 1}clear{/if} {if $smarty.foreach.homeFeaturedProducts.iteration > ($smarty.foreach.homeFeaturedProducts.total - ($smarty.foreach.homeFeaturedProducts.total % $nbItemsPerLine))}last_line{/if}">
			<a class="products_block_img bordercolor" href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'home')}" alt="{$special.legend|escape:html:'UTF-8'}" title="{$special.name|escape:html:'UTF-8'}" /></a><div>
			<span class="price">{if $pricedrop.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}{if !$priceDisplay}{convertPrice price=$pricedrop.price}{else}{convertPrice price=$pricedrop.price_tax_exc}{/if}{/if}</span>
			{if $special.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}<p class="price_container"><span class="price">{if !$priceDisplay}{convertPrice price=$special.price}{else}{convertPrice price=$special.price_tax_exc}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}
					<a class="button" href="{$special.link}" title="{l s='View' mod='pricedrop'}">{l s='View' mod='pricedrop'}</a>
					{if ($special.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $special.available_for_order AND !isset($restricted_country_mode) AND $special.minimal_quantity == 1 AND $special.customizable != 2 AND !$PS_CATALOG_MODE}
						{if ($special.quantity > 0 OR $special.allow_oosp)}
						<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$special.id_product}" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$special.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pricedrop'}">{l s='Add to cart' mod='pricedrop'}</a>
						{else}
						<span class="exclusive">{l s='Add to cart' mod='pricedrop'}</span>
						{/if}
					{else}
						<div style="height:23px;"></div>
					{/if}
			</div>
		</li>
		{/foreach}
	</ul>
</div>
{else}
	<p>{l s='No specials at this time' mod='pricedrop'}</p>
{/if}
</div>
<!-- MODULE Pricedrop Products -->

 

I show the 2 one that i pricedrop, but i olso show the other one that is in the home category.

Can some one help me please.....

 

there is speacial price drop property in product object. so if you look ar blockspecial module and copy that code and it will work

only change smarty $special to $yourvariable

Link to comment
Share on other sites

hi AFemalProdigy.

 

your hack seems perfect for me but i have applied it to my shop and it works fine but the big problem is that the images do not appear.

 

note that i am using a non-default template (elation liquid).

 

see attached "specialsblock.png"

 

any ideas on how to fix this?

 

thanks,

jez...

post-520279-0-61193300-1368883139_thumb.png

Link to comment
Share on other sites

fixed it.

 

i changed the...

 

<a href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'medium')}" alt="{$special.legend|

 

since i am using presta 1.5.3.1 i had to chage "medium" for "home_default" to call my image and not the image name for version 1.4.7.3

 

works great!

 

thanks!

jez...

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

To modify the specials block to display more than 1 product (for PS 1.5.4.0.) I did so:

 

Modified the getRandomSpecial function in classes/Product.php

 

/**
* Get a random special
*
* @param integer $id_lang Language id
* @return array Special
*/

 public static function getRandomSpecial($id_lang, $beginning = false, $ending = false, Context $context = null)
{
 if (!$context)
  $context = Context::getContext();
  $front = true;
 if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
  $front = false;
  $current_date = date('Y-m-d H:i:s');
  $product_reductions = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context, true);
 if ($product_reductions)
 {
  $ids_product = ' AND (';
foreach ($product_reductions as $product_reduction)
  $ids_product .= '( product_shop.`id_product` = '.(int)$product_reduction['id_product'].($product_reduction['id_product_attribute'] ? ' AND product_attribute_shop.`id_product_attribute`='.(int)$product_reduction['id_product_attribute'] :'').') OR';
  $ids_product = rtrim($ids_product, 'OR').')';
  $groups = FrontController::getCurrentCustomerGroups();
  $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
 // Please keep 2 distinct queries because RAND() is an awful way to achieve this result
  $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
FROM `'._DB_PREFIX_.'product` p
  '.Shop::addSqlAssociation('product', 'p').'
  LEFT JOIN  `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product)
  '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1').'
WHERE product_shop.`active` = 1
 '.(($ids_product) ? $ids_product : '').'
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.'
	  )
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_category_default` != 199
GROUP BY product_shop.id_product
ORDER BY RAND() LIMIT 0,3'; // LIMIT the number of products to show (3 in this case)
  $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

foreach($result as $res){
 if($res['id_product']){
 $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
  pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
  p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`,
  DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
  INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
  DAY)) > 0 AS new
  FROM `'._DB_PREFIX_.'product` p
  LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
  p.`id_product` = pl.`id_product`
  AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
			  )
  '.Shop::addSqlAssociation('product', 'p').'
  LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
  Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
  LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
  '.Product::sqlStock('p', 0).'
  WHERE p.id_product = '.(int)$res['id_product'].'
  GROUP BY product_shop.id_product';
													$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

													if($row){
															if ($res['id_product_attribute']){
																	$row['id_product_attribute'] = $res['id_product_attribute'];
															}
															$spe[] = Product::getProductProperties($id_lang, $row);
													  }
											  }
											}
											return $spe;
 }
  else
return false;
}

 

 

 

In Themes/Your_theme_name/Modules/blockspecials/blockspecials.tpl (I modified what it's marked)

 

 

<!-- MODULE Block specials -->

<div id="special_block_right" class="block products_block exclusive blockspecials">

<h4><a href="{$link->getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}</a></h4>

<div class="block_content">

{if $special}

{foreach from=$special item='product' name='special'}

<ul class="products">

<li class="ajax_block_product">

 

<a class="product_image" href="{$product.link}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" alt="{$product.legend|escape:html:'UTF-8'}" title="{$product.name|escape:html:'UTF-8'}" /></a>

<div>

<span class="addtocart"><a href="{$link->getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}</a></span>

</div>

<h3><a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}">{$product.name|escape:html:'UTF-8'}</a></h3>

<p class="product_desc">{$product.description_short|truncate:120:'...'|strip_tags:'UTF-8'}</p>

<span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$product.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}</span>

{if $product.specific_prices}

{assign var='specific_prices' value=$product.specific_prices}

{if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}

<span class="reduction">(-{$specific_prices.reduction * 100|floatval}%)</span>

{/if}

{/if}

<span class="price">{if !$priceDisplay}{displayWtPrice p=$product.price}{else}{displayWtPrice p=$product.price_tax_exc}{/if}</span>

</li>

</ul>

{/foreach}

{else}

<p>{l s='No specials at this time' mod='blockspecials'}</p>

{/if}

</div>

</div>

<!-- /MODULE Block specials -->

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

  • 3 weeks later...

Oki doki, my idea might be helpful also it works. Just use getPricesDrop function and mix specials module with homefeatured like i did in your specials.php. You can also make from homefeatured new specials by changing some stuff which you can find below:

$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));

 

$special = Product::getPricesDrop((int)Context::getContext()->language->id,0,($nb ? $nb : 10));

 

 

 

 

 

 

$this->smarty->assign(array(

'special' => $special,

'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),

'homeSize' => Image::getSize(ImageType::getFormatedName('home')),

$nb is a variable in which i store the quantity of products to be displayed. Ok, than just copy {foreach}...{/foreach} from homefeatured.tpl.

{if $special}

 

{assign var='liHeight' value=250}

{assign var='nbItemsPerLine' value=4}

{assign var='nbLi' value=$special|@count}

{math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}

 

{math equation="nbLines*liHeight" nbLines=$nbLines|ceil liHeight=$liHeight assign=ulHeight}

<ul style="height:{$ulHeight}px;">

{foreach from=$special item=product name=special}

{math equation="(total%perLine)" total=$smarty.foreach.special.total perLine=$nbItemsPerLine assign=totModulo}

{if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}

<li class="product_imageajax_block_product {if $smarty.foreach.special.first}first_item{elseif $smarty.foreach.special.last}last_item{else}item{/if}

{if $smarty.foreach.special.iteration%$nbItemsPerLine == 0}last_item_of_line

{elseif $smarty.foreach.special.iteration%$nbItemsPerLine == 1} {/if}

{if $smarty.foreach.special.iteration > ($smarty.foreach.special.total - $totModulo)}last_line{/if}">

I hope it'll help somebody.

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

To modify the specials block to display more than 1 product (for PS 1.5.4.0.) I did so:

 

Modified the getRandomSpecial function in classes/Product.php

 

/**
* Get a random special
*
* @param integer $id_lang Language id
* @return array Special
*/

 public static function getRandomSpecial($id_lang, $beginning = false, $ending = false, Context $context = null)
{
 if (!$context)
  $context = Context::getContext();
  $front = true;
 if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
  $front = false;
  $current_date = date('Y-m-d H:i:s');
  $product_reductions = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context, true);
 if ($product_reductions)
 {
  $ids_product = ' AND (';
foreach ($product_reductions as $product_reduction)
  $ids_product .= '( product_shop.`id_product` = '.(int)$product_reduction['id_product'].($product_reduction['id_product_attribute'] ? ' AND product_attribute_shop.`id_product_attribute`='.(int)$product_reduction['id_product_attribute'] :'').') OR';
  $ids_product = rtrim($ids_product, 'OR').')';
  $groups = FrontController::getCurrentCustomerGroups();
  $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
 // Please keep 2 distinct queries because RAND() is an awful way to achieve this result
  $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
FROM `'._DB_PREFIX_.'product` p
  '.Shop::addSqlAssociation('product', 'p').'
  LEFT JOIN  `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product)
  '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1').'
WHERE product_shop.`active` = 1
 '.(($ids_product) ? $ids_product : '').'
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.'
	  )
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_category_default` != 199
GROUP BY product_shop.id_product
ORDER BY RAND() LIMIT 0,3'; // LIMIT the number of products to show (3 in this case)
  $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

foreach($result as $res){
 if($res['id_product']){
 $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
  pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
  p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`,
  DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
  INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
  DAY)) > 0 AS new
  FROM `'._DB_PREFIX_.'product` p
  LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
  p.`id_product` = pl.`id_product`
  AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
			  )
  '.Shop::addSqlAssociation('product', 'p').'
  LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
  Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
  LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
  '.Product::sqlStock('p', 0).'
  WHERE p.id_product = '.(int)$res['id_product'].'
  GROUP BY product_shop.id_product';
													$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

													if($row){
															if ($res['id_product_attribute']){
																	$row['id_product_attribute'] = $res['id_product_attribute'];
															}
															$spe[] = Product::getProductProperties($id_lang, $row);
													  }
											  }
											}
											return $spe;
 }
  else
return false;
}

 

 

This code works. but I have a problem. The price without reduction just show 0 for all products. please help for fix it

 

post-650779-0-29167900-1375604144_thumb.jpg

Link to comment
Share on other sites

  • 4 weeks later...

Pdioana I copy and paste your code for the prestashop 1.5 but I have got the following problem:

 

 Undefined index: price_without_reduction (C:\xampp\htdocs\t-shirt_cus\modules\blockspecials\blockspecials.php, line 94)[/color]

 

[color=#000000]how can I fix this I dont know from when comes the "[/color][color=#000000]price_without_reduction" index I check all the tables database related to this sql but i did not found any fields with the name of [/color][color=#000000]"[/color][color=#000000]price_without_reduction"[/color]

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

  • 3 weeks later...

After correcting some missing bits of code from the solution above, I was able to get this to work with no duplicating of the products. However, it is only showing two special products. I see where it says to keep two distinct queries. I am assuming I would need to add more to show more special products? What do I need to edit to show more than two products? Like six products. Thanks!

Hai mam...

 

Pls send me code for add multiple special blockspecial ..

 

Not Repeat product in special block...

 

Regards

 

Azharudeen

Link to comment
Share on other sites

  • 3 weeks later...

hi, is there anyone who uses the block special offers by viewing more products for prestashop 1.5.

you can post it.

thanks

;)

I am using this on PS 1.5.4.0 . It is based on AFemaleProdigy solution on 1.4.7.3. I just changed the picture size to solid sizes (75 px).

 

It is just need to design it in CSS (as anybody wish), but it works.

 

The only problem is the product duplication in this block.

 

I am not PHP coder, so no idea what to do.

 

Anybody any ideas?   

blockspecials.zip

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

  • 5 weeks later...
  • 1 month later...
  • 1 month later...
  • 2 months later...

HERE IS HOW TO EASY SHUFFLE SPECIALS PRODUCTS :

 

in specialsblock.php you have to add :

 

shuffle($specials);

 

just after that $specials were filled, for exemple i had to add it here :

 

 

<<
        if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
        {
            if (!($specials = Product::getPricesDrop((int)$params['cookie']->id_lang, 0, 5)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
                return;

            shuffle($specials);
            $this->smarty->assign(array(
                'specials' => $specials,
                'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
            ));

        }

>>

 

 

( . Y . )

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
I am using prestashop 1.6 and I can not find some correspondences with the codes you have entered. So I carry them below: 

 

blockspecials.tpl 

 


<!-- MODULE Block specials -->

<div id="special_block_right" class="block">

<p class="title_block">

        <a href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" title="{l s='Specials' mod='blockspecials'}">

            {l s='Products in promotion' mod='blockspecials'}

        </a>

    </p>

<div class="block_content products-block">

    

    

    {if $special}

<ul>

        <li class="clearfix">

            <a class="products-block-image" href="{$special.link|escape:'html':'UTF-8'}">

                    <img 

                    class="replace-2x img-responsive" 

                    src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'small_default')|escape:'html':'UTF-8'}" 

                    alt="{$special.legend|escape:'html':'UTF-8'}" 

                    title="{$special.name|escape:'html':'UTF-8'}" />

                </a>

                <div class="product-content">

                <h5>

                        <a class="product-name" href="{$special.link|escape:'html':'UTF-8'}" title="{$special.name|escape:'html':'UTF-8'}">

                            {$special.name|escape:'html':'UTF-8'}

                        </a>

                    </h5>

                    {if isset($special.description_short) && $special.description_short}

                    <p class="product-description">

                            {$special.description_short|strip_tags:'UTF-8'|truncate:40}

                        </p>

                    {/if}

                    <div class="price-box">

                    {if !$PS_CATALOG_MODE}

                        <span class="price special-price">

                                {if !$priceDisplay}

                                    {displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}

                                {/if}

                            </span>

                             {if $special.specific_prices}

                                {assign var='specific_prices' value=$special.specific_prices}

                                {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}

                                    <span class="price-percent-reduction">-{$specific_prices.reduction*100|floatval}%</span>

                                {/if}

                            {/if}

                             <span class="old-price">

                                {if !$priceDisplay}

                                    {displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}

                                {/if}

                            </span>

                        {/if}

                    </div>

                </div>

            </li>

</ul>

<div>

<a 

            class="btn btn-default button button-small" 

            href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" 

            title="{l s='All specials' mod='blockspecials'}">

                <span>{l s='All specials' mod='blockspecials'}<i class="icon-chevron-right right"></i></span>

            </a>

</div>

    {else}

<div>{l s='No specials at this time.' mod='blockspecials'}</div>

    {/if}

</div>

</div>

 

<!-- /MODULE Block specials -->


 

blockspecials.php 

 


if (!defined('_PS_VERSION_'))

exit;

 

class BlockSpecials extends Module

{

private $_html = '';

private $_postErrors = array();

 

    function __construct()

    {

        $this->name = 'blockspecials';

        $this->tab = 'pricing_promotion';

        $this->version = '1.1';

$this->author = 'PrestaShop';

$this->need_instance = 0;

 

$this->bootstrap = true;

parent::__construct();

 

$this->displayName = $this->l('Specials block');

$this->description = $this->l('Adds a block displaying your current discounted products.');

$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);

}

 

public function install()

{

if (!Configuration::get('BLOCKSPECIALS_NB_CACHES'))

Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', 20);

$this->_clearCache('blockspecials.tpl');

 

$success = (

parent::install()

&& $this->registerHook('header')

&& $this->registerHook('addproduct')

&& $this->registerHook('updateproduct')

&& $this->registerHook('deleteproduct')

);

 

if ($success)

{

// Hook the module either on the left or right column

$theme = new Theme(Context::getContext()->shop->id_theme);

if ((!$theme->default_right_column || !$this->registerHook('rightColumn'))

&& (!$theme->default_left_column || !$this->registerHook('leftColumn')))

{

// If there are no colums implemented by the template, throw an error and uninstall the module

$this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one');

parent::uninstall();

return false;

}

}

return $success;

}

 

public function uninstall()

{

$this->_clearCache('blockspecials.tpl');

return parent::uninstall();

}

 

public function getContent()

{

$output = '';

if (Tools::isSubmit('submitSpecials'))

{

Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY'));

Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', (int)Tools::getValue('BLOCKSPECIALS_NB_CACHES'));

$output .= $this->displayConfirmation($this->l('Settings updated'));

}

return $output.$this->renderForm();

}

 

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(4, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 4)));

 

if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))

{

if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))

return;

 

$this->smarty->assign(array(

'special' => $special,

'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),

'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),

));

}

 

return $this->display(__FILE__, 'blockspecials.tpl', (Configuration::get('BLOCKSPECIALS_NB_CACHES') ? $this->getCacheId('blockspecials|'.$random) : null));

}

 

public function hookLeftColumn($params)

{

return $this->hookRightColumn($params);

}

 

     public function hookHeader($params)

{

if (Configuration::get('PS_CATALOG_MODE'))

return ;

$this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all');

}

 

public function hookAddProduct($params)

{

$this->_clearCache('blockspecials.tpl');

}

 

public function hookUpdateProduct($params)

{

$this->_clearCache('blockspecials.tpl');

}

 

public function hookDeleteProduct($params)

{

$this->_clearCache('blockspecials.tpl');

}

 

public function renderForm()

{

$fields_form = array(

'form' => array(

'legend' => array(

'title' => $this->l('Settings'),

'icon' => 'icon-cogs'

),

'input' => array(

array(

'type' => 'switch',

'label' => $this->l('Always display this block'),

'name' => 'PS_BLOCK_SPECIALS_DISPLAY',

'desc' => $this->l('Show the block even if no products are available.'),

'values' => array(

array(

'id' => 'active_on',

'value' => 1,

'label' => $this->l('Enabled')

),

array(

'id' => 'active_off',

'value' => 0,

'label' => $this->l('Disabled')

)

),

),

array(

'type' => 'text',

'label' => $this->l('Number of cached files'),

'name' => 'BLOCKSPECIALS_NB_CACHES',

'desc' => $this->l('Specials are displayed randomly on the front-end, but since it takes a lot of ressources, it is better to cache the results. The cache is reset daily. 0 will disable the cache.'),

),

),

'submit' => array(

'title' => $this->l('Save'),

)

),

);

 

$helper = new HelperForm();

$helper->show_toolbar = false;

$helper->table =  $this->table;

$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));

$helper->default_form_language = $lang->id;

$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;

$helper->identifier = $this->identifier;

$helper->submit_action = 'submitSpecials';

$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;

$helper->token = Tools::getAdminTokenLite('AdminModules');

$helper->tpl_vars = array(

'fields_value' => $this->getConfigFieldsValues(),

'languages' => $this->context->controller->getLanguages(),

'id_language' => $this->context->language->id

);

 

return $helper->generateForm(array($fields_form));

}

 

public function getConfigFieldsValues()

{

return array(

'PS_BLOCK_SPECIALS_DISPLAY' => Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')),

'BLOCKSPECIALS_NB_CACHES' => Tools::getValue('BLOCKSPECIALS_NB_CACHES', Configuration::get('BLOCKSPECIALS_NB_CACHES')),

);

}

}


 

 

 


Can you tell me the changes to be done to bring up more than one product? The module is inserted in the left column (www.xanthe.it). 

thanks

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

To modify the specials block to display more than 1 product (for PS 1.5.4.0.) I did so:

 

Modified the getRandomSpecial function in classes/Product.php

 

/**
* Get a random special
*
* @param integer $id_lang Language id
* @return array Special
*/

  public static function getRandomSpecial($id_lang, $beginning = false, $ending = false, Context $context = null)
{
  if (!$context)
   $context = Context::getContext();
   $front = true;
  if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
   $front = false;
   $current_date = date('Y-m-d H:i:s');
   $product_reductions = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context, true);
  if ($product_reductions)
  {
   $ids_product = ' AND (';
	foreach ($product_reductions as $product_reduction)
   $ids_product .= '( product_shop.`id_product` = '.(int)$product_reduction['id_product'].($product_reduction['id_product_attribute'] ? ' AND product_attribute_shop.`id_product_attribute`='.(int)$product_reduction['id_product_attribute'] :'').') OR';
   $ids_product = rtrim($ids_product, 'OR').')';
   $groups = FrontController::getCurrentCustomerGroups();
   $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
  // Please keep 2 distinct queries because RAND() is an awful way to achieve this result
   $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
	FROM `'._DB_PREFIX_.'product` p
	  '.Shop::addSqlAssociation('product', 'p').'
	  LEFT JOIN  `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product)
	  '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1').'
	WHERE product_shop.`active` = 1
	 '.(($ids_product) ? $ids_product : '').'
	AND p.`id_product` IN (
	SELECT cp.`id_product`
	FROM `'._DB_PREFIX_.'category_group` cg
	LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
	WHERE cg.`id_group` '.$sql_groups.'
		  )
	'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
	AND p.`id_category_default` != 199
	GROUP BY product_shop.id_product
	ORDER BY RAND() LIMIT 0,3'; // LIMIT the number of products to show (3 in this case)
   $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
											  
	foreach($result as $res){
	 if($res['id_product']){
	 $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
	  pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
	  p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`,
	  DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
	  INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
	  DAY)) > 0 AS new
	  FROM `'._DB_PREFIX_.'product` p
	  LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
	  p.`id_product` = pl.`id_product`
	  AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
				  )
	  '.Shop::addSqlAssociation('product', 'p').'
	  LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
	  Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
	  LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
	  '.Product::sqlStock('p', 0).'
	  WHERE p.id_product = '.(int)$res['id_product'].'
	  GROUP BY product_shop.id_product';
														$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
											  
														if($row){
																if ($res['id_product_attribute']){
																		$row['id_product_attribute'] = $res['id_product_attribute'];
																}
																$spe[] = Product::getProductProperties($id_lang, $row);
														  }
												  }
												}
												return $spe;
  }
   else
	return false;
}

 

In Themes/Your_theme_name/Modules/blockspecials/blockspecials.tpl (I modified what it's marked)

 

 

<!-- MODULE Block specials -->

<div id="special_block_right" class="block products_block exclusive blockspecials">

<h4><a href="{$link->getPageLink('prices-drop.php')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}</a></h4>

<div class="block_content">

{if $special}

{foreach from=$special item='product' name='special'}

<ul class="products">

<li class="ajax_block_product">

 

<a class="product_image" href="{$product.link}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" alt="{$product.legend|escape:html:'UTF-8'}" title="{$product.name|escape:html:'UTF-8'}" /></a>

<div>

<span class="addtocart"><a href="{$link->getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}</a></span>

</div>

<h3><a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}">{$product.name|escape:html:'UTF-8'}</a></h3>

<p class="product_desc">{$product.description_short|truncate:120:'...'|strip_tags:'UTF-8'}</p>

<span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$product.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}</span>

{if $product.specific_prices}

{assign var='specific_prices' value=$product.specific_prices}

{if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}

<span class="reduction">(-{$specific_prices.reduction * 100|floatval}%)</span>

{/if}

{/if}

<span class="price">{if !$priceDisplay}{displayWtPrice p=$product.price}{else}{displayWtPrice p=$product.price_tax_exc}{/if}</span>

</li>

</ul>

{/foreach}

{else}

<p>{l s='No specials at this time' mod='blockspecials'}</p>

{/if}

</div>

</div>

<!-- /MODULE Block specials -->

 

 

 

 

I am using prestashop 1.6 and I can not find some correspondences with the codes you have entered. So I carry them below: 
 
blockspecials.tpl 
 
<!-- MODULE Block specials -->
<div id="special_block_right" class="block">
<p class="title_block">
        <a href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" title="{l s='Specials' mod='blockspecials'}">
            {l s='Products in promotion' mod='blockspecials'}
        </a>
    </p>
<div class="block_content products-block">
    
    
    {if $special}
<ul>
        <li class="clearfix">
            <a class="products-block-image" href="{$special.link|escape:'html':'UTF-8'}">
                    <img 
                    class="replace-2x img-responsive" 
                    src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'small_default')|escape:'html':'UTF-8'}" 
                    alt="{$special.legend|escape:'html':'UTF-8'}" 
                    title="{$special.name|escape:'html':'UTF-8'}" />
                </a>
                <div class="product-content">
                <h5>
                        <a class="product-name" href="{$special.link|escape:'html':'UTF-8'}" title="{$special.name|escape:'html':'UTF-8'}">
                            {$special.name|escape:'html':'UTF-8'}
                        </a>
                    </h5>
                    {if isset($special.description_short) && $special.description_short}
                    <p class="product-description">
                            {$special.description_short|strip_tags:'UTF-8'|truncate:40}
                        </p>
                    {/if}
                    <div class="price-box">
                    {if !$PS_CATALOG_MODE}
                        <span class="price special-price">
                                {if !$priceDisplay}
                                    {displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}
                                {/if}
                            </span>
                             {if $special.specific_prices}
                                {assign var='specific_prices' value=$special.specific_prices}
                                {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
                                    <span class="price-percent-reduction">-{$specific_prices.reduction*100|floatval}%</span>
                                {/if}
                            {/if}
                             <span class="old-price">
                                {if !$priceDisplay}
                                    {displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}
                                {/if}
                            </span>
                        {/if}
                    </div>
                </div>
            </li>
</ul>
<div>
<a 
            class="btn btn-default button button-small" 
            href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" 
            title="{l s='All specials' mod='blockspecials'}">
                <span>{l s='All specials' mod='blockspecials'}<i class="icon-chevron-right right"></i></span>
            </a>
</div>
    {else}
<div>{l s='No specials at this time.' mod='blockspecials'}</div>
    {/if}
</div>
</div>
 
<!-- /MODULE Block specials -->
 
blockspecials.php 
 
if (!defined('_PS_VERSION_'))
exit;
 
class BlockSpecials extends Module
{
private $_html = '';
private $_postErrors = array();
 
    function __construct()
    {
        $this->name = 'blockspecials';
        $this->tab = 'pricing_promotion';
        $this->version = '1.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
 
$this->bootstrap = true;
parent::__construct();
 
$this->displayName = $this->l('Specials block');
$this->description = $this->l('Adds a block displaying your current discounted products.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
 
public function install()
{
if (!Configuration::get('BLOCKSPECIALS_NB_CACHES'))
Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', 20);
$this->_clearCache('blockspecials.tpl');
 
$success = (
parent::install()
&& $this->registerHook('header')
&& $this->registerHook('addproduct')
&& $this->registerHook('updateproduct')
&& $this->registerHook('deleteproduct')
);
 
if ($success)
{
// Hook the module either on the left or right column
$theme = new Theme(Context::getContext()->shop->id_theme);
if ((!$theme->default_right_column || !$this->registerHook('rightColumn'))
&& (!$theme->default_left_column || !$this->registerHook('leftColumn')))
{
// If there are no colums implemented by the template, throw an error and uninstall the module
$this->_errors[] = $this->l('This module need to be hooked in a column and your theme does not implement one');
parent::uninstall();
return false;
}
}
return $success;
}
 
public function uninstall()
{
$this->_clearCache('blockspecials.tpl');
return parent::uninstall();
}
 
public function getContent()
{
$output = '';
if (Tools::isSubmit('submitSpecials'))
{
Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY'));
Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', (int)Tools::getValue('BLOCKSPECIALS_NB_CACHES'));
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
return $output.$this->renderForm();
}
 
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(4, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 4)));
 
if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)))
{
if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return;
 
$this->smarty->assign(array(
'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
));
}
 
return $this->display(__FILE__, 'blockspecials.tpl', (Configuration::get('BLOCKSPECIALS_NB_CACHES') ? $this->getCacheId('blockspecials|'.$random) : null));
}
 
public function hookLeftColumn($params)
{
return $this->hookRightColumn($params);
}
 
     public function hookHeader($params)
{
if (Configuration::get('PS_CATALOG_MODE'))
return ;
$this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all');
}
 
public function hookAddProduct($params)
{
$this->_clearCache('blockspecials.tpl');
}
 
public function hookUpdateProduct($params)
{
$this->_clearCache('blockspecials.tpl');
}
 
public function hookDeleteProduct($params)
{
$this->_clearCache('blockspecials.tpl');
}
 
public function renderForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Always display this block'),
'name' => 'PS_BLOCK_SPECIALS_DISPLAY',
'desc' => $this->l('Show the block even if no products are available.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Number of cached files'),
'name' => 'BLOCKSPECIALS_NB_CACHES',
'desc' => $this->l('Specials are displayed randomly on the front-end, but since it takes a lot of ressources, it is better to cache the results. The cache is reset daily. 0 will disable the cache.'),
),
),
'submit' => array(
'title' => $this->l('Save'),
)
),
);
 
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table =  $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitSpecials';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
 
return $helper->generateForm(array($fields_form));
}
 
public function getConfigFieldsValues()
{
return array(
'PS_BLOCK_SPECIALS_DISPLAY' => Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')),
'BLOCKSPECIALS_NB_CACHES' => Tools::getValue('BLOCKSPECIALS_NB_CACHES', Configuration::get('BLOCKSPECIALS_NB_CACHES')),
);
}
}
 
 
 
Can you tell me the changes to be done to bring up more than one product? The module is inserted in the left column (www.xanthe.it). 
thanks

 

 

Gracias me sirvió, hay que modificar esos 2 archivos como dices

 

Excelente !!!

 

Sirve para la versión 1.6

 

---------------------

 

Thanks helped me, you have to modify these 2 files as you say 
 
Excellent !!!
 
Used to version 1.6
Link to comment
Share on other sites

Comparto mi código para obtener en forma de grid el listado, se agregò la clase al li <li class="ajax_block_product col-xs-12 col-sm-6 col-md-4 first-in-line last-line first-item-of-tablet-line first-item-of-mobile-line last-mobile-line hovered">
 
In Themes/Your_theme_name/Modules/blockspecials/blockspecials.tpl
 
 
Saludos !!!!  :D 
 
{*
* 2007-2014 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 [email protected] 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 <[email protected]>
*  @copyright  2007-2014 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
 
<!-- MODULE Block specials -->
<div id="special_block_right" class="block_rodin">
<h3 class="title_block">
        <img class="replace-2x" src="http://localhost/rodin/img/cms/icono_naranja.png" alt="" width="75" height="103">
        <a href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" title="{l s='Specials' mod='blockspecials'}">
            {l s='Specials' mod='blockspecials'}
        </a>
    </h3>
<div class="block_content products-block">
 
 
    {if $special}
    <ul>
    {foreach from=$special item='product' name='special'}
 
        <li class="ajax_block_product col-xs-12 col-sm-6 col-md-4 first-in-line last-line first-item-of-tablet-line first-item-of-mobile-line last-mobile-line hovered">
            <a class="products-block-image" href="{$product.link|escape:'html':'UTF-8'}">
                    <img 
                    class="replace-2x img-responsive" 
                    src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}" 
                    alt="{$product.legend|escape:'html':'UTF-8'}" 
                    title="{$product.name|escape:'html':'UTF-8'}" />
                </a>
                <div class="right-block">
                <h5>
                        <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}">
                            {$product.name|escape:'html':'UTF-8'}
                        </a>
                    </h5>
                    {if isset($product.description_short) && $product.description_short}
                    <p class="product-description">
                            {$product.description_short|strip_tags:'UTF-8'|truncate:40}
                        </p>
                    {/if}
                    <div class="price-box">
                    {if !$PS_CATALOG_MODE}
                        <span class="price special-price">
                                {if !$priceDisplay}
                                    {displayWtPrice p=$product.price}{else}{displayWtPrice p=$product.price_tax_exc}
                                {/if}
                            </span>
                             {if $product.specific_prices}
                                {assign var='specific_prices' value=$product.specific_prices}
                                {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))}
                                    <span class="price-percent-reduction">-{$specific_prices.reduction*100|floatval}%</span>
                                {/if}
                            {/if}
                             <span class="old-price">
                                {if !$priceDisplay}
                                    {displayWtPrice p=$product.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}
                                {/if}
                            </span>
                        {/if}
                    </div>
                </div>
            </li>
{/foreach}
        </ul>         
<div>
<a 
            class="btn btn-default button button-small" 
            href="{$link->getPageLink('prices-drop')|escape:'html':'UTF-8'}" 
            title="{l s='All specials' mod='blockspecials'}">
                <span>{l s='All specials' mod='blockspecials'}<i class="icon-chevron-right right"></i></span>
            </a>
</div> 
    {else}
<div>{l s='No specials at this time.' mod='blockspecials'}</div>
    {/if}
</div>
</div>
<!-- /MODULE Block specials -->

Link to comment
Share on other sites

  • 4 months later...
  • 10 months later...

After correcting some missing bits of code from the solution above, I was able to get this to work with no duplicating of the products. However, it is only showing two special products. I see where it says to keep two distinct queries. I am assuming I would need to add more to show more special products? What do I need to edit to show more than two products? Like six products. Thanks!

nice

Link to comment
Share on other sites

×
×
  • Create New...