Jump to content
davidtnb

How do I add more than 1 special in the blockspecials module?

Recommended Posts

Is there anyway to add more specials to the specials block? Right now it only has one, I would like to edit it so it would stretch down to the end of my page, by adding more specials.



I got it to produce 2 of the same items using this, but unable to show 2 DIFFERENT items:
http://img195.imageshack.us/img195/2681/sdfadsadffadsfdsafdasfs.png

Then I got it to show multiple special blocks, but they are all still the same item:
http://img199.imageshack.us/img199/6024/t4w54ewtretreytreterter.png




Anyone know what to edit to do this?

Share this post


Link to post
Share on other sites

Try mahoob sulemans, Slideproducts, its much better, search slideproducts in forum or google.

John

Share this post


Link to post
Share on other sites
Try mahoob sulemans, Slideproducts, its much better, search slideproducts in forum or google.

John


Yep, got that awesome module installed also. Its just my boss wants me to have more than 1 special on the right side of the page because I removed that ugly "new products" module because it was nothing but spam, and now there is a lot of space under the specials.

Anyone know how to add more than 1?

Share this post


Link to post
Share on other sites

Here is how I would do it. Rewrite the getRandomSpecial function to return more than one row as follows (change LIMIT 2 to how many specials you want):

static public function getRandomSpecial($id_lang, $beginning = false, $ending = false)
{
   global $link, $cookie;

   $currentDate = date('Y-m-d');
   $result = Db::getInstance()->ExecuteS('
   SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
       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` = '.intval($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` = '.intval($id_lang).')
   LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
   WHERE (`reduction_price` > 0 OR `reduction_percent` > 0)
   '.((!$beginning AND !$ending) ?
       'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.$currentDate.'\' AND `reduction_to` >= \''.$currentDate.'\'))'
   :
       ($beginning ? 'AND `reduction_from` <= \''.$beginning.'\'' : '').($ending ? 'AND `reduction_to` >= \''.$ending.'\'' : '')).'
   AND p.`active` = 1
   ORDER BY RAND() LIMIT 2');

   if (!$result)
       return false;

   foreach ($result AS $row)
       $rows[] = Product::getProductProperties($id_lang, $row);

   return $rows;
}


Change the hookRightColumn function of modules/blockspecials/blockspecials.php to:

function hookRightColumn($params)
{
   global $smarty;

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

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



Replace modules/blockspecials/blockspecials.tpl with:

<!-- MODULE Block specials -->

{l s='Specials' mod='blockspecials'}

{if $specials}

{foreach from=$specials item=special name=products}




{$special.name|escape:htmlall:'UTF-8'}
{displayWtPrice p=$special.price_without_reduction}
               {if $special.reduction_percent}(-{$special.reduction_percent}%){/if}
{displayWtPrice p=$special.price}

{/foreach}



{l s='All specials' mod='blockspecials'}

{else}

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


<!-- /MODULE Block specials -->



You may need to mess around with the CSS to get the specials to display neatly. I hope this helps.

Share this post


Link to post
Share on other sites

where i Rewrite the getRandomSpecial?


Here is how I would do it. Rewrite the getRandomSpecial function to return more than one row as follows (change LIMIT 2 to how many specials you want):

static public function getRandomSpecial($id_lang, $beginning = false, $ending = false)
{
   global $link, $cookie;

   $currentDate = date('Y-m-d');
   $result = Db::getInstance()->ExecuteS('
   SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
       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` = '.intval($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` = '.intval($id_lang).')
   LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
   WHERE (`reduction_price` > 0 OR `reduction_percent` > 0)
   '.((!$beginning AND !$ending) ?
       'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.$currentDate.'\' AND `reduction_to` >= \''.$currentDate.'\'))'
   :
       ($beginning ? 'AND `reduction_from` <= \''.$beginning.'\'' : '').($ending ? 'AND `reduction_to` >= \''.$ending.'\'' : '')).'
   AND p.`active` = 1
   ORDER BY RAND() LIMIT 2');

   if (!$result)
       return false;

   foreach ($result AS $row)
       $rows[] = Product::getProductProperties($id_lang, $row);

   return $rows;
}


Change the hookRightColumn function of modules/blockspecials/blockspecials.php to:

function hookRightColumn($params)
{
   global $smarty;

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

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



Replace modules/blockspecials/blockspecials.tpl with:

<!-- MODULE Block specials -->

{l s='Specials' mod='blockspecials'}

{if $specials}

{foreach from=$specials item=special name=products}




{$special.name|escape:htmlall:'UTF-8'}
{displayWtPrice p=$special.price_without_reduction}
               {if $special.reduction_percent}(-{$special.reduction_percent}%){/if}
{displayWtPrice p=$special.price}

{/foreach}



{l s='All specials' mod='blockspecials'}

{else}

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


<!-- /MODULE Block specials -->



You may need to mess around with the CSS to get the specials to display neatly. I hope this helps.

Share this post


Link to post
Share on other sites

The getRandomSpecial function is in classes/Product.php

Share this post


Link to post
Share on other sites

hi!
I met the same problem! Is there someone to help us?

Thanks!

Share this post


Link to post
Share on other sites

Worked great for me in 1.3.0.1
I just did what Rocky said plus a few changes in global.css

like:
/* Block specials */

.blockspecials li {
float: left;
clear: none;
width: 100%;
}

Share this post


Link to post
Share on other sites

Thank You Rocky,

I don't what they did working in 1.3 and 1.2.5 for me

Thank You Rocky,

Share this post


Link to post
Share on other sites

Hello

I am also trying to extend the module so it displays more than 1 product in the right side.

My product.php file does not have the LIMIT 2 option.

In my file it is as this ORDER BY RAND()'); So i added the limit option so its the same as in this thread but now it just says no specials in the box.

Not sure if it will be different in a newer version?? Hope someone can help

I m running Prestashop Version 1.3.3

Share this post


Link to post
Share on other sites
Hello

I am also trying to extend the module so it displays more than 1 product in the right side.

My product.php file does not have the LIMIT 2 option.

In my file it is as this ORDER BY RAND()'); So i added the limit option so its the same as in this thread but now it just says no specials in the box.

Not sure if it will be different in a newer version?? Hope someone can help

I m running Prestashop Version 1.3.3


Same problem here. PS v.1.3.2

Thanks

Share this post


Link to post
Share on other sites
Here is how I would do it. Rewrite the getRandomSpecial function to return more than one row as follows (change LIMIT 2 to how many specials you want):

static public function getRandomSpecial($id_lang, $beginning = false, $ending = false)
{
   global $link, $cookie;

   $currentDate = date('Y-m-d');
   $result = Db::getInstance()->ExecuteS('
   SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
       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` = '.intval($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` = '.intval($id_lang).')
   LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
   WHERE (`reduction_price` > 0 OR `reduction_percent` > 0)
   '.((!$beginning AND !$ending) ?
       'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.$currentDate.'\' AND `reduction_to` >= \''.$currentDate.'\'))'
   :
       ($beginning ? 'AND `reduction_from` <= \''.$beginning.'\'' : '').($ending ? 'AND `reduction_to` >= \''.$ending.'\'' : '')).'
   AND p.`active` = 1
   ORDER BY RAND() LIMIT 2');

   if (!$result)
       return false;

   foreach ($result AS $row)
       $rows[] = Product::getProductProperties($id_lang, $row);

   return $rows;
}


Change the hookRightColumn function of modules/blockspecials/blockspecials.php to:

function hookRightColumn($params)
{
   global $smarty;

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

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



Replace modules/blockspecials/blockspecials.tpl with:

<!-- MODULE Block specials -->

{l s='Specials' mod='blockspecials'}

{if $specials}

{foreach from=$specials item=special name=products}




{$special.name|escape:htmlall:'UTF-8'}
{displayWtPrice p=$special.price_without_reduction}
               {if $special.reduction_percent}(-{$special.reduction_percent}%){/if}
{displayWtPrice p=$special.price}

{/foreach}



{l s='All specials' mod='blockspecials'}

{else}

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


<!-- /MODULE Block specials -->



You may need to mess around with the CSS to get the specials to display neatly. I hope this helps.



3 years later but... you're BOSS!

Share this post


Link to post
Share on other sites

Hi All, I too am facing the same problem with prestashop version 1.4.1 dont know where to change the code (add the LIMIT) to get specials display more than 1 item if any one is having solution for that please brief me the steps to do that.

 

THANKS IN ADVANCE

Share this post


Link to post
Share on other sites

I think it doesn't work in 1.4 the code is a little bit different.

Share this post


Link to post
Share on other sites

I also did everything according Rocky´s instructions and the blockspecials shows "No products in specials" although there are two. I use PS 1.4.0.17 version.

Share this post


Link to post
Share on other sites

try this: working in 1.4.7.0

 

change only /modules/blockspecials/blockspecials.tpl

from:

{if $special}
 <ul class="products">
.....
<span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
  </li>
 </ul>
 <p>
...

 

to:

{if $specials !== false}
 <ul class="products">
  {foreach from=$specials item='special' name='products'}
	   <li class="product_image">
.....
		  <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
 </li>
	{/foreach}
 </ul>
			<p>
...

 

and

/modules/blockspecials/blockspecials.php

 

from:

if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang)) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
  return;
 $smarty->assign(array(
  'special' => $special,

to:

if (!$specials = Product::getRandomSpecial((int)($params['cookie']->id_lang)) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
  return;
  $specials = array();
  for ($i = 1; $i <= 10; $i++)
$specials[] = Product::getRandomSpecial((int)($params['cookie']->id_lang));
 $smarty->assign(array(
  'specials' => $specials,

 

in function for ($i = 1; $i <= 10; $i++)

$i <= 10

10 is number of products

Edited by lakombrada (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Thanks lakombrada! Works well. Just one thing... is it duplicating products if there are less specials than the number stated, is it possible to stop it duplicating?

many thanks!

Share this post


Link to post
Share on other sites

Hi rocky... Thanx for post.

Changes for "blockspecials.tpl" you mentioned doesn't look good. Please resubmit your changes for this file....

Share this post


Link to post
Share on other sites

i have a problem that it displays the same product more than once even if you dont show them all i have 49 products and if i show 20 at least 3-4 have doubles in there its weird

Share this post


Link to post
Share on other sites

Done! Thanx for support to all. Working nice

Share this post


Link to post
Share on other sites

hello

 

 

I have two products with special price and it is duplicating onde of them

 

How could we fix that?

Share this post


Link to post
Share on other sites

try this: working in 1.4.7.0

 

change only /modules/blockspecials/blockspecials.tpl

from:

{if $special}
 <ul class="products">
.....
<span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
  </li>
 </ul>
 <p>
...

 

to:

{if $specials !== false}
 <ul class="products">
  {foreach from=$specials item='special' name='products'}
	   <li class="product_image">
.....
		  <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
 </li>
	{/foreach}
 </ul>
			<p>
...

 

and

/modules/blockspecials/blockspecials.php

 

from:

if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang)) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
  return;
 $smarty->assign(array(
  'special' => $special,

to:

if (!$specials = Product::getRandomSpecial((int)($params['cookie']->id_lang)) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
  return;
  $specials = array();
  for ($i = 1; $i <= 10; $i++)
$specials[] = Product::getRandomSpecial((int)($params['cookie']->id_lang));
 $smarty->assign(array(
  'specials' => $specials,

 

in function for ($i = 1; $i <= 10; $i++)

$i <= 10

10 is number of products

 

Got this and no products (1.4.8.3):

 

Notice: Undefined variable: special in /var/www/user/data/www/site.ru/modules/blockspecials/blockspecials.php on line 110
Notice: Undefined variable: specials in /var/www/user/data/www/site.ru/tools/smarty/sysplugins/smarty_internal_data.php on line 291

Edited by Kerm (see edit history)

Share this post


Link to post
Share on other sites

I want to confirm that this works with 1.4.8.2, but I am also having the same duplication issue. Because this is using the Random function, it will generate random and sometimes duplicate products. We need to modify the code so it is not requesting a random product, but rather x number of products in the specials list, perhaps starting with the most recent. Or, the code needs to be modified to prevent duplication. Unfortunately, i do not know how to do either. I think a lot of people would appreciate having it though. Anyone here know how to make either of the two work?

 

Here is the code that works for me to generate multiple products in the specials block (with occasional duplications):

 

blockspecials.tpl

 

<!-- 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 $specials !== false}



 <ul class="products">
    {foreach from=$specials item='special' name='products'}
  <li class="product_image">
   <a href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'medium')}" alt="{$special.legend|escape:html:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$special.name|escape:html:'UTF-8'}" /></a>
  </li>
  <li>
   <h5><a href="{$special.link}" title="{$special.name|escape:html:'UTF-8'}">{$special.name|escape:html:'UTF-8'}</a></h5>
   <span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/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="reduction">(-{$specific_prices.reduction*100|floatval}%)</span>
		  {/if}
		 {/if}
   <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
  </li>
	    {/foreach}
 </ul>
 <p>
  <a href="{$link->getPageLink('prices-drop.php')}" title="{l s='All specials' mod='blockspecials'}" class="button_large">{l s='All specials' mod='blockspecials'}</a>
 </p>
{else}
 <p>{l s='No specials at this time' mod='blockspecials'}</p>
{/if}
</div>
</div>
<!-- /MODULE Block specials -->

 

blockspecials.php - note: This is just the rightColumn function. I did not have to change anything else. Change the number 2 to whatever number of products you want to show.

 

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;
  $specials = array();
	  for ($i = 1; $i <= 2; $i++)
$specials[] = Product::getRandomSpecial((int)($params['cookie']->id_lang));
 $smarty->assign(array(
  'specials' => $specials,
  'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
  'mediumSize' => Image::getSize('medium'),
 ));
 return $this->display(__FILE__, 'blockspecials.tpl');
}

  • Like 1

Share this post


Link to post
Share on other sites

I was able to get Bug00 solution working with some edits to what he had posted for the code. However, that solution only displays two specials and I need six specials. Anyone know how to modify that to show more that two? See my post here...

 

http://www.prestasho...post__p__921805

Edited by AFemaleProdigy (see edit history)

Share this post


Link to post
Share on other sites

solution to achieve this is realy simple. you just need to call function

 

Product::getPricesDrop(_langID_, 0, 10, false, NULL, NULL, false, false), within your blockspecials.php instead of getingrandom special. where 10 is number of products..

 

then just foreach new special walue as it get array than.

 

why are you doing it so difficult?

 

 

 

 

public function hookHomee($params)

{

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

return ;

 

global $smarty;

 

$smarty->assign(array(

'specials' => Product::getPricesDrop(6, 0, 10, false, NULL, NULL, false, false),

'mediumSize' => Image::getSize('medium')

));

 

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

}

 

public function hookHome($params)

{

return $this->hookHomee($params);

}

 

 

 

 

 

 

 

{if $specials}

<ul>

{foreach from=$specials item='special' name='specialProducts'}

<li>

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

<div>

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

<p>

<span class="pricecolor price-discount">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/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="pricecolor reduction">(-{$specific_prices.reduction*100|floatval}%)</span>

{/if}

{/if}

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

</p>

</div>

</li>

 

{/foreach}

</ul>

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

{else}

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

{/if}

  • Like 3

Share this post


Link to post
Share on other sites

@AFemaleProdigy

 

in post # 31, you are using following loop in blockspecials.php

 

 

for ($i = 1; $i <= 2; $i++)

 

If you modify your array variables to higher value i.e

 

for ($i = 1; $i <= 7; $i++)

You will achieve your required result.

Share this post


Link to post
Share on other sites

i'm working with 1.5 and i make the changes that @AFemaleProdigy post and now not even 1 article shows up, i don't know if it is because the version of prestashop, if is that the case, can any of you give me any solution?

thanks and sorrry about my awful english : (

Share this post


Link to post
Share on other sites

i'm working with 1.5 and i make the changes that @AFemaleProdigy post and now not even 1 article shows up, i don't know if it is because the version of prestashop, if is that the case, can any of you give me any solution?

thanks and sorrry about my awful english : (

 

I attached my modified files for you to see here...

 

http://www.prestashop.com/forums/index.php?/topic/117765-quick-tutorial-how-to-add-multiple-specials-to-specials-block/page__fromsearch__1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More