MaxPayneNSK Posted August 29, 2015 Share Posted August 29, 2015 Hello. Have a question, how make random product show in blockspecials on hookDisplayHomeTabContent, Presta 1.6 I would be very grateful Link to comment Share on other sites More sharing options...
vekia Posted August 29, 2015 Share Posted August 29, 2015 you want to display random products from whole catalog or display products randomly from specials only? Link to comment Share on other sites More sharing options...
MaxPayneNSK Posted August 30, 2015 Author Share Posted August 30, 2015 you want to display random products from whole catalog or display products randomly from specials only? Hi Vekia, need random specials on main page in tab discounts. Link to comment Share on other sites More sharing options...
vekia Posted September 1, 2015 Share Posted September 1, 2015 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 More sharing options...
MaxPayneNSK Posted September 2, 2015 Author Share Posted September 2, 2015 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 1 Link to comment Share on other sites More sharing options...
cfocket Posted January 5, 2016 Share Posted January 5, 2016 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 More sharing options...
hakeryk2 Posted September 14, 2016 Share Posted September 14, 2016 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 More sharing options...
lagoacity Posted December 27, 2017 Share Posted December 27, 2017 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 More sharing options...
bellini13 Posted December 27, 2017 Share Posted December 27, 2017 BlockSpecials::$cache_specials = Product::getPricesDrop(intval($params['cookie']->id_lang), 0, 200); shuffle($PricesDrop); array_splice($PricesDrop, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR') ); Where is $PricesDrop defined? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now