Jump to content

[SOLVED]How to show more than 1 special products in prestashop?


Recommended Posts

As per this topic http://www.prestasho...in-new-product/

 

Now I want to know how to can show 4 products in special block, currently it is showing 1.

ps7.png

 

However I have added some products as giving them discount by percent and by amount for some.

When I click All Special hyperlink then on next page these special products are visible, then why not on home page?

ps8.png

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

I have tried

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

 PRODUCT INFO HERE
   	 {/if}
  	 {/foreach}

 

Then out put is

ps9.png

It is showing 4 items now but all images are same all products are same...so it is use less.

When I refresh page then it changes the products but again all 4 are same.

ps10.png

 

I want to have all 4 special products without repeating as above.

Edited by rajesh.yadav (see edit history)
Link to comment
Share on other sites

I did it actually, but you have to use another query in the source php file. You can try with Product::getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false,

$order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null)

 

Cheers!

Link to comment
Share on other sites

This is my code in file blockspecial.php I have created a new hook by this it is being displayed on center column on home page.

Now please let me know where should I have to put your code in my existing code shown below:

public function hookDisplayHome($params)
{
 if (Configuration::get('PS_CATALOG_MODE'))
  return ;
 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),
  'smallSize' => Image::getSize(ImageType::getFormatedName('small')),
 ));
 return $this->display(__FILE__, 'blockspecials.tpl');
}

Link to comment
Share on other sites

public function hookDisplayHome($params)

{

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

return ;

if (!($specials =Product::getPricesDrop($this->context->language->id,0,10))

return;

$this->smarty->assign(array(

'specials' => $specials,

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

'smallSize' => Image::getSize(ImageType::getFormatedName('small')),

));

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

}

  • Like 1
Link to comment
Share on other sites

Now my site is now working it is showing white page after applying above code.

So I tried

if (!($special =Product::getPricesDrop($this->context->language->id,0,10))

instead of your

if (!($specials =Product::getPricesDrop($this->context->language->id,0,10))

but still white page.

So I am undoing your code.

Link to comment
Share on other sites

public function hookDisplayHome($params)
   {
   if (Configuration::get('PS_CATALOG_MODE'))
   return ;
   if (!($specials =Product::getPricesDrop($this->context->language->id,0,10)))
  return;
 $this->smarty->assign(array(
 'specials' => $specials,
 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
 'smallSize' => Image::getSize(ImageType::getFormatedName('small')),
 ));
 return $this->display(__FILE__, 'blockspecials.tpl');
}

 

what should I write

special or specials?

 

I've applied above code, am I making mistake?

Link to comment
Share on other sites

Sorry but I've completed only 1 project in prestashop.

I am magento developer,

Prestashop is new for me.

If I use special then it is showing view buttons and they're working fine.

then why thumb images are not being displayed.

 

anyway I dont know what should I have to do now <_<

Edited by rajesh.yadav (see edit history)
Link to comment
Share on other sites

Quote:

 

public function hookDisplayHome($params)

{

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

return ;

if (!($specials =Product::getPricesDrop($this->context->language->id,0,10)))

return;

$this->smarty->assign(array(

'specials' => $specials,

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

'smallSize' => Image::getSize(ImageType::getFormatedName('small')),

));

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

}

 

 

Mixing up your vars don't work in either Prestashop nor Magento ;-)

Change red $special in $specials

And see if this brings us further

pascal

Link to comment
Share on other sites

Did it but still it says

No product specials are available at this time.

Then I gone through product>prices>and changed the start date to yesterday i.e. 8August 2013 to 31Aug2013

 

Even I had put $special in tpl but still not working,

 

But nothing happened.

I thought current date might be issue.

Edited by rajesh.yadav (see edit history)
Link to comment
Share on other sites

As you have supported me so as per your request I'm sharing here my code snippet for blockspecial.tpl [full page code]

{*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [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-2013 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 products_block exclusive blockspecials">
<p class="title_block"><a href="{$link->getPageLink('prices-drop')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}</a></p>
<div class="block_content">
{if $special}
 <ul class="products clearfix">
 {foreach from=$special item='product' name='special'}
	    {if $smarty.foreach.special.index < 4}
  <li class="product_image">
   <a href="{$product.link}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'small_default')}" alt="{$product.legend|escape:html:'UTF-8'}" height="{$smallSize.height}" width="{$smallSize.width}" title="{$product.name|escape:html:'UTF-8'}" /></a><br/>

  </li>

  <li>

   {if !$PS_CATALOG_MODE}
 {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"><span>-{$specific_prices.reduction*100|floatval}%</span></span>
  {/if}
 {/if}
   {/if}


 <p class="s_title_block"><a href="{$product.link}" title="{$product.name|escape:html:'UTF-8'}">{$product.name|escape:html:'UTF-8'}</a></p>
   {if !$PS_CATALOG_MODE}
 <span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$product.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}</span>
 <span class="price">{if !$priceDisplay}{displayWtPrice p=$product.price}{else}{displayWtPrice p=$product.price_tax_exc}{/if}</span>
   {/if}













   {/if}
    {/foreach}

  </li>
 </ul>



 <p>
  <a href="{$link->getPageLink('prices-drop')}" class="link-all" title="{l s='All specials' mod='blockspecials'}">» {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 -->

 

 

and for blockspecials.php

 

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [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-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
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 = '0.8';
 $this->author = 'PrestaShop';
 $this->need_instance = 0;
 parent::__construct();
 $this->displayName = $this->l('Specials block');
 $this->description = $this->l('Adds a block displaying current product specials.');
}
public function install()
{
 return (parent::install() AND $this->registerHook('rightColumn')  AND $this->registerHook('header'));
}
public function getContent()
{
 $output = '<h2>'.$this->displayName.'</h2>';
 if (Tools::isSubmit('submitSpecials'))
 {
  Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)(Tools::getValue('always_display')));
  $output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';
 }
 return $output.$this->displayForm();
}
public function displayForm()
{
 return '
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
  <fieldset>
   <legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
   <label>'.$this->l('Always display this block.').'</label>
   <div class="margin-form">
 <input type="radio" name="always_display" id="display_on" value="1" '.(Tools::getValue('always_display', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
 <input type="radio" name="always_display" id="display_off" value="0" '.(!Tools::getValue('always_display', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) ? 'checked="checked" ' : '').'/>
 <label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
 <p class="clear">'.$this->l('Show the block even if no product is available.').'</p>
   </div>
   <center><input type="submit" name="submitSpecials" value="'.$this->l('Save').'" class="button" /></center>
  </fieldset>
 </form>';
}
public function hookRightColumn($params)
{
 if (Configuration::get('PS_CATALOG_MODE'))
  return ;
 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),
  'smallSize' => Image::getSize(ImageType::getFormatedName('small')),
 ));
 return $this->display(__FILE__, 'blockspecials.tpl');
}



public function hookDisplayHome($params)
   {
   if (Configuration::get('PS_CATALOG_MODE'))
   return ;
   if (!($special =Product::getPricesDrop($this->context->language->id,0,10)))
  return;
 $this->smarty->assign(array(
 'special' => $special,
 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
 'smallSize' => Image::getSize(ImageType::getFormatedName('small')),
 ));
 return $this->display(__FILE__, 'blockspecials.tpl');
}



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');
}
}

  • Like 2
Link to comment
Share on other sites

In my homepage or feature products, specials or specials block is not working.

 

In this link

 

http://www.realamberjewelry.com/prices-drop

 

it is working.

 

I try both special and specials for this code.

 

 

public function hookDisplayHome($params)

{

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

return ;

if (!($specials =Product::getPricesDrop($this->context->language->id,0,10))

return;

 

$this->smarty->assign(array(

'specials' => $specials,

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

'smallSize' => Image::getSize(ImageType::getFormatedName('small')),

));

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

}

Link to comment
Share on other sites

Read this

 

How to call and right column content to center column?

 

Suppose I want to show new product from right to center colum then...

 

I will go to its module folder and then will open its php file i.e. blocknewproducts.php

 

here i can see

public function hookRightColumn($params){

 

// functions code do not change this code

 

 

 

}

 

no need to change any code i will just copy and paste above code just below it.

 

public function hookRightColumn($params){

 

// functions code do not change this code

 

}

 

Now i will change the name of pasted function as hookDisplayHome($params)

 

So now the code will be

public function hookDisplayHome($params){

 

// functions code do not change this code

 

}

 

Now I will go to admin panel and position and new product then transplant a module

then i will select displayHome

save.

Link to comment
Share on other sites

Thanks Rajesh now its working,

 

But now there is another problem

 

It is showing 4 items now but all images are same all products are same...so it is use less.

When I refresh page then it changes the products but again all 4 are same.

 

can u or Nemo1 or any other explain with code.

I am new in prestashop

 

My site is: http://www.realamberjewelry.com/

 

thanks advance

Link to comment
Share on other sites

Hi Jahi,

 

Did you change the product selector to: (see red code)

 

public function hookDisplayHome($params)

{

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

return ;

if (!($specials =Product::getPricesDrop($this->context->language->id,0,10))

return;

 

$this->smarty->assign(array(

'specials' => $specials,

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

'smallSize' => Image::getSize(ImageType::getFormatedName('small')),

));

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

}

 

pascal

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

 

I actually works with prestashop 1.5.5.0. I use this solution when i change my version of prestashop from 1.5.3.1 to 1.5.5.0 because my

changes doesn't works anymore.

 

So, thank you for this code.

 

Nevertheless, i have a problem. Now, i can see all my specials products but i want to display only 2 products.

 

So my question is : How can i choose the number of products i want to display ?

 

Thank you for your answers.

Link to comment
Share on other sites

  • 4 weeks later...

Hello everybody,

 

glad there are some people who found solution to the problem. I also have one. I want to show more than one image in right sidebar. As Rajesh wrote 2 files that user must replace, I've tried to do that, but still only one item shows. The most interesting part is that I've tried to delete both blockspecial.tpl in module dir and in template dir - nothing happens, still same result (one product) is showing, so I'm not talking about changing those files because there are no effect after all. PHP file works without problem. I'm using standard default Prestashop 1.5 template, but seems to be difficult to call out this function. Anyway, hope somebody could help me, it's a bit bothering when you should take all day to search for a solution. Thank you for your help in advance!

 

P.S.

 

Seems it was cache, but after all, I do get absolutely unneeded items, when I click on link „see more“, I see proper products, check in http://namuakcentai.lt/

 

Thanks for reply.

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

  • 1 month later...

you mean code in #24 post?

No the #22 , I just copy pasted it ( using default theme with default position )

 

but it didn't change anything ( keep clearing cache to be sure )

 

I edited both tmp & php , I'm not familiar with coding but I though this should have been possible with #22

 

Regardsing #24 I believe it's for repositioning / horizintal displaying , I just default position

 

much appreciated

john

Link to comment
Share on other sites

ok, so what .tpl file you changed? 

sometimes theme directory has got this module file - if so - it's necessary to change code there

I changed the blockspecial.tmp  ... rather replaced it as above .

 

So I use the default theme and replace th blockspecial.tmp and php as suggested above . 

 

I spent some time and when i did "other"  codes a.p. some other forums and one non forum I can see changes ( it doen't work either but I see changes )

 

So I can't believe it's cache as the others reacted immediately to changes .

 

Maybe "Rasq" has a solution with his code ? 

 

thanks

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Dear friends, I would like to ask you a hand. I installed the module you speak of prestashop 1.6, but can having product specials, none appears. Could you explain why?

the most important questions:

you've got products with dropped prices?

Link to comment
Share on other sites

Dear Vekia, I put the "special" products, they are. In practice, in the bottom of the home nothing appears, despite, checking the Live Edit, the module is present. This problem may be caused by the fact that I'm using version 1.6 of prestashop? Or something else? How can I fix this?

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • 10 months later...
×
×
  • Create New...