Jump to content

Random blockspecials on hookDisplayHomeTabContent


Recommended Posts

that's great

 

in blockbestsellers.php there is a function:
 

	protected function getBestSellers($params)
	{
		if (Configuration::get('PS_CATALOG_MODE'))
			return false;

		if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, (int)Configuration::get('PS_BLOCK_BESTSELLERS_TO_DISPLAY'))))
			return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false);

		$currency = new Currency($params['cookie']->id_currency);
		$usetax = (Product::getTaxCalculationMethod((int)$this->context->customer->id) != PS_TAX_EXC);
		foreach ($result as &$row)
			$row['price'] = Tools::displayPrice(Product::getPriceStatic((int)$row['id_product'], $usetax), $currency);

		return $result;
	}

change last line to return shuffle($result);

Link to comment
Share on other sites

If need random blockspecial on homepage, change public function hookDisplayHomeTab on code

 

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


if (!$this->isCached('tab.tpl', $this->getCacheId('blockspecials-tab')))
BlockSpecials::$cache_specials = Product::getPricesDrop(intval($params['cookie']->id_lang), 0, 200); shuffle($PricesDrop); array_splice($PricesDrop, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR') );


if (BlockSpecials::$cache_specials)
{ 
shuffle(BlockSpecials::$cache_specials); 
array_splice(BlockSpecials::$cache_specials, ($nb ? $nb : 12)); 
}


if (BlockSpecials::$cache_specials === false)
return false;


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

Here '12' - the amount of goods on the page

 

 

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hi guys, 

 

I hooked my blockSpecials to hookDisplayHomeTabContent and don't get a random display of my products.

 

I tried your solution on the homespecials.php by pasting them inside public function hookDisplayHomeTabContent($params){}

 

I don't get any good results. Is there a tiny piece of code I'm missing?

 

Thanks very much,

Clément.

Link to comment
Share on other sites

  • 8 months later...

 

 

change last line to return shuffle($result);

 

I dunno why but in my case it was showing only one product but this
 
shuffle($result);
return $result;
 
is working properly.
 
Ok, that works for Block Bestseller but how about blockspecials home? It is really annoying that it is showin only few specials with highest price. Any idea?
Link to comment
Share on other sites

  • 1 year later...

When i do this:

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


if (!$this->isCached('tab.tpl', $this->getCacheId('blockspecials-tab')))
BlockSpecials::$cache_specials = Product::getPricesDrop(intval($params['cookie']->id_lang), 0, 200); shuffle($PricesDrop); array_splice($PricesDrop, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR') );


if (BlockSpecials::$cache_specials)
{ 
shuffle(BlockSpecials::$cache_specials); 
array_splice(BlockSpecials::$cache_specials, ($nb ? $nb : 12)); 
}


if (BlockSpecials::$cache_specials === false)
return false;


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

 

Appears this 

Warning: array_splice() expects parameter 1 to be array, null given in /home/winespir/public_html/shop/modules/blockspecials/blockspecials.php on line 151.

 

Why?

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...