amcm112 Posted May 16, 2014 Share Posted May 16, 2014 Hi Vekia ! Tks for your kind help... I have made changes... however seems nothing new happend still looking only the same producs.. here is our proyect http://electronicamtz.com Link to comment Share on other sites More sharing options...
vekia Posted May 16, 2014 Share Posted May 16, 2014 clear shop cache now ! also, try to use this one: public function hookDisplayHome($params) { $this->_cacheProducts(); $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } $this->smarty->assign( array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), ) ); return $this->display(__FILE__, 'homefeatured.tpl'); } 1 Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 Binggoo!!! Veika! we did it..! However now its shown 10 products, where can I change to only 8 as the default? Tks so much! Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 ohh yess I found it... in the same code Im sorry for my last reply... Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 with this change now is working for 1.6.0.5 random products from all catalogue and how many products to show.. Tks again Vekia after some days of try and fail.. finally working. Great help Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 16, 2014 Share Posted May 16, 2014 Why in my version 1.5.6.1 don't function it Link to comment Share on other sites More sharing options...
vekia Posted May 16, 2014 Share Posted May 16, 2014 array_splice($products, ($nb ? $nb : 10)); change 10 to 8 sry for my mistake Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 16, 2014 Share Posted May 16, 2014 same story don't function... Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 16, 2014 Share Posted May 16, 2014 I will go to sleep sad Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 cicciotargatona you try to change some of the examples vekia provided before in this same post, try modifing your homefeatured.php after this you may make it work. Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 17, 2014 Share Posted May 17, 2014 cicciotargatona you try to change some of the examples vekia provided before in this same post, try modifing your homefeatured.php after this you may make it work. Amcm112 I have try really all the examples, but nothing change. I know that the codes of Vekia are corrects, but in my version of prestashop don't work it, I'm not lucky,,, Link to comment Share on other sites More sharing options...
vekia Posted May 17, 2014 Share Posted May 17, 2014 same story don't function... my answer was to amcm112 Link to comment Share on other sites More sharing options...
vekia Posted May 17, 2014 Share Posted May 17, 2014 Amcm112 I have try really all the examples, but nothing change. I know that the codes of Vekia are corrects, but in my version of prestashop don't work it, I'm not lucky,,, the only one thing you have to do is change this line: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); to: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); and it was already said somewhere, in various topic i think can you try, please? 1 Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 the only one thing you have to do is change this line: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); to: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); and it was already said somewhere, in various topic i think can you try, please? I have try but nothing have change, i lose my mind... if (!defined('_PS_VERSION_')) exit; class HomeFeatured extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; $this->version = '1.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Featured products on the homepage.'); $this->description = $this->l('Displays featured products in the middle of your homepage.'); } function install() { $this->_clearCache('homefeatured.tpl'); Configuration::updateValue('HOME_FEATURED_NBR', 8); if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header') || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('deleteproduct') ) return false; return true; } public function uninstall() { $this->_clearCache('homefeatured.tpl'); return parent::uninstall(); } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitHomeFeatured')) { $nbr = (int)Tools::getValue('nbr'); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('An invalid number of products has been specified.'); else Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr)); if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); else $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br /> <label>'.$this->l('Define the number of products to be displayed.').'</label> <div class="margin-form"> <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" /> <p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p> </div> <center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $output; } public function hookDisplayHeader($params) { $this->hookHeader($params); } public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all'); } public function hookDisplayHome($params) { $this->_cacheProducts(); $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } $this->smarty->assign( array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), ) ); return $this->display(__FILE__, 'homefeatured.tpl'); } public function hookAddProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookUpdateProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookDeleteProduct($params) { $this->_clearCache('homefeatured.tpl'); } } Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 you use two instances of code, second one overwrite first - proper one remove all modifications that you made and change only one line that i suggested to change Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 <?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 HomeFeatured extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; $this->version = '1.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Featured products on the homepage.'); $this->description = $this->l('Displays featured products in the middle of your homepage.'); } function install() { $this->_clearCache('homefeatured.tpl'); Configuration::updateValue('HOME_FEATURED_NBR', 8); if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header') || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('deleteproduct') ) return false; return true; } public function uninstall() { $this->_clearCache('homefeatured.tpl'); return parent::uninstall(); } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitHomeFeatured')) { $nbr = (int)Tools::getValue('nbr'); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('An invalid number of products has been specified.'); else Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr)); if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); else $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br /> <label>'.$this->l('Define the number of products to be displayed.').'</label> <div class="margin-form"> <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" /> <p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p> </div> <center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $output; } public function hookDisplayHeader($params) { $this->hookHeader($params); } public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all'); } public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); } return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } public function hookAddProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookUpdateProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookDeleteProduct($params) { $this->_clearCache('homefeatured.tpl'); } } Voilà but nothing change But i display 16 products in home page, change something it? Thanks Vekia for the help Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 clear shop cache or change: public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); shuffle($products); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); } return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } to public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); return $this->display(__FILE__, 'homefeatured.tpl'); } 1 Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 Done! Again nothing... Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 are you 100% sure that you use homefeatured module? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 Hahahahaha yes Vekia /modules/homefeatured/homefeatured.php come in my shop, maybe you found something of anomalous http://luxelumi.com Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 believe me or not, but you don't use default module search for "addhomefeatured" i think that this is proper module Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 believe me or not, but you don't use default module search for "addhomefeatured" i think that this is proper module Fuckkk you're right! hahaha, and how i can edit? <?php if (!defined('_PS_VERSION_')) exit; class AddHomeFeatured extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'addhomefeatured'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Custom'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Add Featured Products on the homepage'); $this->description = $this->l('Displays Featured Products in the middle of your homepage.'); } function install() { if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader')) return false; return true; } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitAddHomeFeatured')) { $nbr = (int)(Tools::getValue('nbr')); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('Invalid number of products'); else Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr)); if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); else $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' <div class="clearfix"></div> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <fieldset><legend>'.$this->l('Settings').'</legend> <p>'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'</p><br /> <label>'.$this->l('Number of products displayed').'</label> <div class="margin-form"> <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" /> <p class="clear">'.$this->l('The number of products displayed on homepage (default: 10).').'</p> </div> <center><input type="submit" name="submitAddHomeFeatured" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $output; } function hookHeader($params) { $this->context->controller->addCSS($this->_path.'css/addhomefeatured.css'); } public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); $p=array(); for($i=0;$i<count($products);$i++){ $product=$products[$i]; unset ($pid); $pid=$product['id_product']; $sql= "SELECT * FROM `"._DB_PREFIX_."image` WHERE `id_product` = '{$pid}' AND cover = '0' ORDER BY `id_image` "; $results = Db::getInstance()->ExecuteS($sql); @$result=$results['0']; $p[$pid]=$result['id_image']; } $this->smarty->assign('addimages',$p); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'), )); return $this->display(__FILE__, 'addhomefeatured.tpl'); } } Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 change this line: $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); with line that i suggested you to change before Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 No show me an error page blank Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 Parse error: syntax error, unexpected 'exit' (T_EXIT) in /homez.808/luxelumi/www/modules/addhomefeatured/addhomefeatured.php on line 1 Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 show me your actual code Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 <?php if (!defined('_PS_VERSION_')) exit; class AddHomeFeatured extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'addhomefeatured'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Custom'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Add Featured Products on the homepage'); $this->description = $this->l('Displays Featured Products in the middle of your homepage.'); } function install() { if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader')) return false; return true; } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitAddHomeFeatured')) { $nbr = (int)(Tools::getValue('nbr')); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('Invalid number of products'); else Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr)); if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); else $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' <div class="clearfix"></div> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <fieldset><legend>'.$this->l('Settings').'</legend> <p>'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'</p><br /> <label>'.$this->l('Number of products displayed').'</label> <div class="margin-form"> <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" /> <p class="clear">'.$this->l('The number of products displayed on homepage (default: 10).').'</p> </div> <center><input type="submit" name="submitAddHomeFeatured" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $output; } function hookHeader($params) { $this->context->controller->addCSS($this->_path.'css/addhomefeatured.css'); } public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true); $p=array(); for($i=0;$i<count($products);$i++){ $product=$products[$i]; unset ($pid); $pid=$product['id_product']; $sql= "SELECT * FROM `"._DB_PREFIX_."image` WHERE `id_product` = '{$pid}' AND cover = '0' ORDER BY `id_image` "; $results = Db::getInstance()->ExecuteS($sql); @$result=$results['0']; $p[$pid]=$result['id_image']; } $this->smarty->assign('addimages',$p); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'), )); return $this->display(__FILE__, 'addhomefeatured.tpl'); } } Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 ah function now! but show only one product Link to comment Share on other sites More sharing options...
vekia Posted May 18, 2014 Share Posted May 18, 2014 your code has these wierdy spaces between lines? in addition, in what software you're chanigng this file? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 18, 2014 Share Posted May 18, 2014 vekia now function with the spaces between lines, but show only one prodcut, not 16 Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 22, 2014 Share Posted May 22, 2014 vekia now function with the spaces between lines, but show only one prodcut, not 16 News? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 24, 2014 Share Posted May 24, 2014 SOLVED $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb : 8)); 1 Link to comment Share on other sites More sharing options...
ignaciocontreras Posted May 25, 2014 Share Posted May 25, 2014 which is the right path to locate "addhomefeatured" ? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 26, 2014 Share Posted May 26, 2014 /www/modules/addhomefeatured Link to comment Share on other sites More sharing options...
iGiorgis Posted May 28, 2014 Share Posted May 28, 2014 (edited) Can I have random products (12) but from all "home" products? I use the default theme of Presta 1.6.0.6! what files must change? and what code? (I dont find the above codes at my homefeatured.php) My "Homefeatured.php" is different from other people here. and how i disable the caching for this module? thanks a lot for the help Edited May 28, 2014 by iGiorgis (see edit history) Link to comment Share on other sites More sharing options...
gopetsquad Posted June 3, 2014 Share Posted June 3, 2014 This code works perfectly on 1.6.0.6 Many thanks to Vekia and cicciotargatona. public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); return $this->display(__FILE__, 'homefeatured.tpl');} 3 Link to comment Share on other sites More sharing options...
Sharak Posted June 5, 2014 Share Posted June 5, 2014 (edited) I found many solutions for showing homefeatured products randomly, but how to display random products from whole offer instead just from homefeatured? Edited June 5, 2014 by Sharak (see edit history) Link to comment Share on other sites More sharing options...
LineTV Posted June 20, 2014 Share Posted June 20, 2014 Works in 1.5.4.1 :-) Thank a lot ! Would this work in PS 1.6? Link to comment Share on other sites More sharing options...
gopetsquad Posted June 20, 2014 Share Posted June 20, 2014 Would this work in PS 1.6? @LineTV -- YES, See my post above....Works with the code I printed out Link to comment Share on other sites More sharing options...
LineTV Posted June 21, 2014 Share Posted June 21, 2014 This code works perfectly on 1.6.0.6 Many thanks to Vekia and cicciotargatona. public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); return $this->display(__FILE__, 'homefeatured.tpl');} I was also wondering - If I want to display ALL products randomly as they are being added onto the site, can I use this code, what should I change in it... can any one help answer? Link to comment Share on other sites More sharing options...
Sharak Posted June 23, 2014 Share Posted June 23, 2014 http://www.prestashop.com/forums/topic/336602-how-to-display-random-products/ Here's the separate thread for that matter. I think we have to try some admin functions for that as there isn't any for loading all products in front end. AdminProductsController loads list of all products. We just need to separate products according to display configuration (throw out disabled, out of stock - if shop doesn't allow buying , etc) and generate small list out of it. Easy to say, hard to make Link to comment Share on other sites More sharing options...
conidig Posted October 11, 2014 Share Posted October 11, 2014 i tried many solutions but nothing worked, here is my code if someone could help me public function hookDisplayHome($params) { if (!$this->isCached('homefeatured_mod.tpl', $this->getCacheId('homefeatured_mod'))) { $category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); if(method_exists('Product','getProductsImgs')) { $image_array=array(); for($i=0;$i<count($products);$i++) { if(isset($products[$i]['id_product'])) $image_array[$products[$i]['id_product']]= Product::getProductsImgs($products[$i]['id_product']); } $this->smarty->assign('productimg',(isset($image_array) AND $image_array) ? $image_array : NULL); } $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); } return $this->display(__FILE__, 'homefeatured_mod.tpl', $this->getCacheId('homefeatured_mod')); } public function hookAddProduct($params) { $this->_clearCache('homefeatured_mod.tpl'); } Link to comment Share on other sites More sharing options...
cycleelcyc Posted April 23, 2015 Share Posted April 23, 2015 (edited) This code works perfectly on 1.6.0.6 Many thanks to Vekia and cicciotargatona. public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); return $this->display(__FILE__, 'homefeatured.tpl');} works on PS 1.6.0.8 thanks!! Edited April 23, 2015 by cycleelcyc (see edit history) Link to comment Share on other sites More sharing options...
Vikingo Amelio Posted August 19, 2015 Share Posted August 19, 2015 Any body can help me please, i'm trying all post but i can't do it ( My prestashop 1.5.6.2 My homefeatured.php code: <?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.or...ses/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.or...ses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class HomeFeatured extends Module { private $_html = ''; private $_postErrors = array(); function __construct() { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; $this->version = '1.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Featured products on the homepage.'); $this->description = $this->l('Displays featured products in the middle of your homepage.'); } function install() { $this->_clearCache('homefeatured.tpl'); Configuration::updateValue('HOME_FEATURED_NBR', 8); if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header') || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('deleteproduct') ) return false; return true; } public function uninstall() { $this->_clearCache('homefeatured.tpl'); return parent::uninstall(); } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitHomeFeatured')) { $nbr = (int)Tools::getValue('nbr'); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('An invalid number of products has been specified.'); else Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr)); if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('<br />', $errors)); else $output .= $this->displayConfirmation($this->l('Your settings have been updated.')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"> <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br /> <label>'.$this->l('Define the number of products to be displayed.').'</label> <div class="margin-form"> <input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" /> <p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p> </div> <center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $output; } public function hookDisplayHeader($params) { $this->hookHeader($params); } public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all'); } public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); } return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } public function hookAddProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookUpdateProduct($params) { $this->_clearCache('homefeatured.tpl'); } public function hookDeleteProduct($params) { $this->_clearCache('homefeatured.tpl'); } } Link to comment Share on other sites More sharing options...
fashiondrobe Posted April 14, 2016 Share Posted April 14, 2016 Hi All The code: -- public function hookDisplayHome($params){$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));/*$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));*/$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb);shuffle($products);$this->smarty->assign(array('products' => $products,'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),'homeSize' => Image::getSize('home_default'),));return $this->display(__FILE__, 'homefeatured.tpl');} -- is not showing my items in random. Please help.. www.fashiondrobe.in Regards Jasbir Singh Link to comment Share on other sites More sharing options...
cycleelcyc Posted April 24, 2016 Share Posted April 24, 2016 any idea to make random featured available products only? thanks. i am with PS 1.6.0.9 Link to comment Share on other sites More sharing options...
sebayutekstil Posted May 19, 2016 Share Posted May 19, 2016 (edited) Hi... I think better just use the function "transplant a modules". ---> Modules & Services --> positions Select module "Featured products on the homepage", then transplant to where you want to display. (displayHomeTabContent) After that, go to module "Featured products on the homepage" --> Modules & Services --> Modules & Services --> Featured products on the homepage Setting here whatever the product you want to display. presta ver - 1.6.15 Edited May 19, 2016 by sebayutekstil (see edit history) 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