rakepl Posted April 15, 2012 Share Posted April 15, 2012 For another visiting or refreshing page (from one ip or different ip) site shows different product on featured products page. Please give any hint or module that can do that ? Thank you. Link to comment Share on other sites More sharing options...
jhnstcks Posted April 15, 2012 Share Posted April 15, 2012 Add shuffle($products); in your homefeatured.php file at line 100 which should make it look something like function hookHome($params) { global $smarty; $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10)); shuffle($products); $smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); 13 Link to comment Share on other sites More sharing options...
rakepl Posted April 16, 2012 Author Share Posted April 16, 2012 Thank you, I will give a try and report it Link to comment Share on other sites More sharing options...
rakepl Posted April 16, 2012 Author Share Posted April 16, 2012 WOWOW, Thank you very much, it's work !! We need person in this forum like you Where I can learn some stuffs like that ? Once again, thank you ! Link to comment Share on other sites More sharing options...
artman Posted July 20, 2012 Share Posted July 20, 2012 Hi jhnstcks! By chance would you happen to know how to assign products as ‘featured products’ so they display on the homepage? Art Link to comment Share on other sites More sharing options...
jhnstcks Posted July 20, 2012 Share Posted July 20, 2012 Hi jhnstcks! By chance would you happen to know how to assign products as ‘featured products’ so they display on the homepage? Art Have a read through the user guide http://doc.prestashop.com/display/PS14/Adding+Products+and+Product+Categories#AddingProductsandProductCategories-DefaultCategoryandCatalogDisplay 1 Link to comment Share on other sites More sharing options...
artman Posted July 20, 2012 Share Posted July 20, 2012 Thanks! That was very useful. I probably would have been trying to figure this out for the next 12 hours before giving up to go back to sleep. You're a life saver jhnstcks! Link to comment Share on other sites More sharing options...
ysco Posted July 21, 2012 Share Posted July 21, 2012 (edited) Better is to add this code, $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Cause the above posted by jhnstcks shows only random at home and place it only at a different position ( every time the same products) the code posted will do the following. Lets say i have 12 items to show add home that you define in the home featured module, but i add 50 products in category and also marked home then it will randomly shows all 50 products and not only the 12 as you will have with jhnstcks code. Great thanks for this useful code goes to IWAN1979 website with code can be found here http://iwanmadan.com/prestashop- random-product-listing/ Regards, ysco.. Edited July 21, 2012 by ysco (see edit history) 8 Link to comment Share on other sites More sharing options...
Vilas Posted September 30, 2012 Share Posted September 30, 2012 (edited) Dear Friend, I need help from you to configure my store. I am facing issue related to home featured module. I have set 16 product to be shown randomly on homepage. But products are not appearing properly on page. It will be great if you help me to resolve it. It will be great if you help me. My site url is Many thanks in advance. Regards Edited November 8, 2012 by Vilas (see edit history) Link to comment Share on other sites More sharing options...
Xav' Posted October 11, 2012 Share Posted October 11, 2012 Hello everyone ! Is there a solution to randomize the same module in 1.5 ? Thank you. Link to comment Share on other sites More sharing options...
jihasibrahim Posted October 16, 2012 Share Posted October 16, 2012 I want to display different products for different countries using IP. Is it possible or any module available. Please help me with this. Link to comment Share on other sites More sharing options...
idseo Posted November 5, 2012 Share Posted November 5, 2012 Better is to add this code, $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Cause the above posted by jhnstcks shows only random at home and place it only at a different position ( every time the same products) the code posted will do the following. Lets say i have 12 items to show add home that you define in the home featured module, but i add 50 products in category and also marked home then it will randomly shows all 50 products and not only the 12 as you will have with jhnstcks code. Great thanks for this useful code goes to IWAN1979 website with code can be found here http://iwanmadan.com/prestashop- random-product-listing/ Regards, ysco.. Tested on PS 1.5 and work fiine 4 Link to comment Share on other sites More sharing options...
Totti Posted November 5, 2012 Share Posted November 5, 2012 in this way, however, are mixed only the first products. I would like to randomly mix all products in the database Link to comment Share on other sites More sharing options...
go2pub Posted November 27, 2012 Share Posted November 27, 2012 Better is to add this code, $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Cause the above posted by jhnstcks shows only random at home and place it only at a different position ( every time the same products) the code posted will do the following. Lets say i have 12 items to show add home that you define in the home featured module, but i add 50 products in category and also marked home then it will randomly shows all 50 products and not only the 12 as you will have with jhnstcks code. Great thanks for this useful code goes to IWAN1979 website with code can be found here http://iwanmadan.com/prestashop- random-product-listing/ Regards, ysco.. Works perfectly in 1.5.2 Thanks Link to comment Share on other sites More sharing options...
BoKr Posted December 1, 2012 Share Posted December 1, 2012 (edited) Is this change then correct? Or did I enter it at the wrong place? function hookHome($params) { global $smarty; $category = new Category(1, (int)Configuration::get('PS_LANG_DEFAULT')); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); /*ITO SHUFFLE right place herE?*/ $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } $smarty->assign(array( 'products' => $category->getProducts((int)$params['cookie']->id_lang, 1, ($nb ? $nb : 10)), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); } Edited December 1, 2012 by B.Köring (see edit history) Link to comment Share on other sites More sharing options...
Kashi Posted January 20, 2013 Share Posted January 20, 2013 Yes this works in 1.5.3.1 too! Eveh with changed reference category (I changed it to 888 see below). It is all very nice this way. But when I change languages, no featured products are found to display on the homepage. Does anyone here know how to make the featured products appear on the omepages in other languages than the default language? This is the resume of the code I using the info from the posts above (thank you all for the input): public function hookDisplayHome($params) { $category = new Category(888, Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 5000); 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'); } ================== But, if I change languages from the default EN to NL, no featured products are displayed on the homepage anymore! Does someone know a solution for that? Don't have a clue Link to comment Share on other sites More sharing options...
patrizia.vergassola Posted January 21, 2013 Share Posted January 21, 2013 Add shuffle($products); in your homefeatured.php file at line 100 which should make it look something like function hookHome($params) { global $smarty; $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10)); shuffle($products); $smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); Hi everyone, anyone knows in which class I can find the getProducts function? I need to duplicate it and add a filter. Thanks in advance! Patrizia Link to comment Share on other sites More sharing options...
Neurona Dreams Posted January 28, 2013 Share Posted January 28, 2013 Hi everyone, anyone knows in which class I can find the getProducts function? I need to duplicate it and add a filter. Thanks in advance! Patrizia This link should help you. http://www.collinsharper.com/documentation/prestashop/class_product_core.html# Link to comment Share on other sites More sharing options...
virtualunlock Posted January 28, 2013 Share Posted January 28, 2013 Works perfectly in 1.5.2 Thanks 1.5.3 also perfectly !! Thanks Link to comment Share on other sites More sharing options...
15ruso Posted February 13, 2013 Share Posted February 13, 2013 Do you get code for presta 1.4.6.2 ????? Code function hookHome($params) { global $smarty; $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10)); shuffle($products); $smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); is good but don´t show randomly products............. a this code for version 1.4.6.2 is not compatible...... $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Link to comment Share on other sites More sharing options...
eloddevil Posted February 23, 2013 Share Posted February 23, 2013 (edited) Thx ! Edited February 23, 2013 by eloddevil (see edit history) Link to comment Share on other sites More sharing options...
All22 Posted February 25, 2013 Share Posted February 25, 2013 Works fine in 1.5.3. Kashibabu, what about small change like this: $products = $category->getProducts((int)Context::getContext()->language->id, 1, 100); if ($products) {shuffle($products);array_splice($products, ($nb ? $nb : 10)); Languages seem to work fine. Link to comment Share on other sites More sharing options...
Innar.Hunt Posted March 9, 2013 Share Posted March 9, 2013 Better is to add this code, $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Cause the above posted by jhnstcks shows only random at home and place it only at a different position ( every time the same products) the code posted will do the following. Lets say i have 12 items to show add home that you define in the home featured module, but i add 50 products in category and also marked home then it will randomly shows all 50 products and not only the 12 as you will have with jhnstcks code. Great thanks for this useful code goes to IWAN1979 website with code can be found here http://iwanmadan.com/prestashop- random-product-listing/ Regards, ysco.. Works for 1.4.7.3 ! Link to comment Share on other sites More sharing options...
artofadornment Posted March 17, 2013 Share Posted March 17, 2013 Hey, could something like this work for the Specials block? I'd like to try it but have no idea where to put any code... Link to comment Share on other sites More sharing options...
fixgear Posted April 1, 2013 Share Posted April 1, 2013 you guys ROCK! i stumbled upon this and implemented it in 1.5.3 and it is AWESOME so far. kashibabu, i have my site in spanish and english for now (more langs to come) and the original code posted by "ysco" a page back works for me in both languages. you can see it working at http://www.fixgear.info . ysco, so, basically, your code will pull randomly from any products i associate with the "home" category? you see, i am adding products now to my store and so far have only added in one category so i have no way to test until i add to more categories. awesome so far though!!! saludos, jer... Link to comment Share on other sites More sharing options...
fixgear Posted April 1, 2013 Share Posted April 1, 2013 BTW, ysco, i have a question. i have tweaked the "accessories" tab on my product pages to show related products instead since my products do not have accessories. could i apply your code to that section so the related products shuffle like that? if so, what code would i paste in and where? see http://www.fixgear.info/index.php?id_product=13&controller=product&id_lang=1 for what i mean. just look at the tabs beneath the product and click the "Related Items" tab. thanks!!! jer... Link to comment Share on other sites More sharing options...
fixgear Posted April 2, 2013 Share Posted April 2, 2013 hmmm... now that i think about it, i would not want ALL products to shuffle on a category page so i think that the code by jhnstcks would work better but CAN IT BE APPLIED TO category pages that list the products in that category so they shuffle each time the page loads? anyone? in what file and on what line would the code go? thanks, jer... Link to comment Share on other sites More sharing options...
af2p Posted April 11, 2013 Share Posted April 11, 2013 can you help me with my featured products? I purchased a template from Templatemonster.com and I have another file, (prestashop 1.5.3.1) 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 = '0.9'; $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() { if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header')) return false; return true; } 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('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 = ' <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('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="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) { $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)); $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'); } } Link to comment Share on other sites More sharing options...
ano Posted April 15, 2013 Share Posted April 15, 2013 (edited) can you help me with my featured products? I purchased a template from Templatemonster.com and I have another file, (prestashop 1.5.3.1) 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 = '0.9'; $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() { if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header')) return false; return true; } public function getContent() { $output = ' [b] '.$this->displayName.'[/b] '; if (Tools::isSubmit('submitHomeFeatured')) { $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(' ', $errors)); else $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { $output = ' [img='.$this->_path.]'.$this->l('Settings').' '.$this->l('In order to add products to your homepage, just add them to the "home" category.').' '.$this->l('Number of products displayed').' '.$this->l('The number of products displayed on homepage (default: 10).').' '; 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) { $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)); $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'); } } Between (bottom): $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); $this->smarty->assign(array( Add: $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } It'll be: $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( That's all Edited April 15, 2013 by ano (see edit history) 1 Link to comment Share on other sites More sharing options...
gngnet Posted April 18, 2013 Share Posted April 18, 2013 Hi, I've slightly modified the Home Featured module to include the randomised option for folks that don't wish to modify the php code and also make it easier to disable the random selection if required. In the configure option for the home featured module I've add an option to select the amount of products to randomly pick from. If you set this to say 100, you featured products page will grab the first 100 products from your home category, shuffle them up and then pick out the amount of products that you have set to be shown. To easily replace you existing module, simply go into the admin area, select the modules tab, locate the existing Home Featured module and select delete. You then select Add a new module, click the browse button and point to the homefeatured.zip file that you have download (homefeatured.zip). Install it by clicking install and then click configure. In the configuration simply set the amount of products you wish to be displayed on the featured area as usual and then set the amount of products you wish to randomly pick from. If you set this to 0 then the random feature will be disabled and you will be back to the standard functionality of the original Home Featured module. Hope this helps... 5 Link to comment Share on other sites More sharing options...
fixgear Posted April 29, 2013 Share Posted April 29, 2013 (edited) hi all. i was wondering why only a limited amount of products were in the "pool" of products to be chosen randomly when i had all of my products selected to the "Home" category but i figured it out so i wanted to share it here. change the "100" in... $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); to the amt. of products you want to be candidates to appear on the home featured. if you leave it at 100 you limit that to the first 100 active products that you have added to your site. i changed mine to 400 to include all of my products. saludos, jez... Edited April 29, 2013 by fixgear (see edit history) Link to comment Share on other sites More sharing options...
Fidlimidly Posted May 6, 2013 Share Posted May 6, 2013 Hi, I've slightly modified the Home Featured module to include the randomised option for folks that don't wish to modify the php code and also make it easier to disable the random selection if required. In the configure option for the home featured module I've add an option to select the amount of products to randomly pick from. If you set this to say 100, you featured products page will grab the first 100 products from your home category, shuffle them up and then pick out the amount of products that you have set to be shown. To easily replace you existing module, simply go into the admin area, select the modules tab, locate the existing Home Featured module and select delete. You then select Add a new module, click the browse button and point to the homefeatured.zip file that you have download (homefeatured.zip). Install it by clicking install and then click configure. In the configuration simply set the amount of products you wish to be displayed on the featured area as usual and then set the amount of products you wish to randomly pick from. If you set this to 0 then the random feature will be disabled and you will be back to the standard functionality of the original Home Featured module. Hope this helps... Works in 1.5.4.1 :-) Thank a lot ! 1 Link to comment Share on other sites More sharing options...
sworld Posted May 6, 2013 Share Posted May 6, 2013 Works in 1.5.4 Thank a lot ! :-) Link to comment Share on other sites More sharing options...
HairMaker.Gr Posted May 8, 2013 Share Posted May 8, 2013 Hi, I've slightly modified the Home Featured module to include the randomised option for folks that don't wish to modify the php code and also make it easier to disable the random selection if required. In the configure option for the home featured module I've add an option to select the amount of products to randomly pick from. If you set this to say 100, you featured products page will grab the first 100 products from your home category, shuffle them up and then pick out the amount of products that you have set to be shown. To easily replace you existing module, simply go into the admin area, select the modules tab, locate the existing Home Featured module and select delete. You then select Add a new module, click the browse button and point to the homefeatured.zip file that you have download (homefeatured.zip). Install it by clicking install and then click configure. In the configuration simply set the amount of products you wish to be displayed on the featured area as usual and then set the amount of products you wish to randomly pick from. If you set this to 0 then the random feature will be disabled and you will be back to the standard functionality of the original Home Featured module. Hope this helps... I try in 1.5.3.1 the module it works in all browsers,(chrome- firefox - safari.) but not in IE from 8 until 10 version.they dint show the photos of the products.Any solution for this bug for me. it happen and in others ?? or only to me. Thanks 2 Link to comment Share on other sites More sharing options...
euronamibia Posted May 11, 2013 Share Posted May 11, 2013 I try in 1.5.3.1 the module it works in all browsers,(chrome- firefox - safari.) but not in IE from 8 until 10 version.they dint show the photos of the products.Any solution for this bug for me. it happen and in others ?? or only to me. Thanks very good ... thanks 1 Link to comment Share on other sites More sharing options...
navid68 Posted July 18, 2013 Share Posted July 18, 2013 hI gngnet, it works for me as well, can I suggest you to add it in the category of free modules in this forum? The link is http://www.prestashop.com/forums/forum/144-free-modules/ and it's a great source of modules. Thanks Navid Link to comment Share on other sites More sharing options...
virtualunlock Posted August 3, 2013 Share Posted August 3, 2013 Add shuffle($products); in your homefeatured.php file at line 100 which should make it look something like function hookHome($params) { global $smarty; $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10)); shuffle($products); $smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); Thank you!!! Link to comment Share on other sites More sharing options...
projectpb Posted August 31, 2013 Share Posted August 31, 2013 $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); } Was useing this on 1.5.4.1 it worked fine no longer works in 1.5.5 Help please Thanks Jeff Link to comment Share on other sites More sharing options...
projectpb Posted September 2, 2013 Share Posted September 2, 2013 hairmania fix in post 34 works in 1.5.5 Thank You Jeff Link to comment Share on other sites More sharing options...
maximo88 Posted September 5, 2013 Share Posted September 5, 2013 Don't work for me in 1.5.5 homefeatured.zip 10.52KB 92 downloads). Link to comment Share on other sites More sharing options...
vekia Posted September 6, 2013 Share Posted September 6, 2013 Don't work for me in 1.5.5 homefeatured.zip 10.52KB 92 downloads). you've got some error messages ? if so, can you share them? Link to comment Share on other sites More sharing options...
PrestaSOO Posted September 8, 2013 Share Posted September 8, 2013 (edited) There is no different when you call some products on Prestashop 1.5.5. Please upload some screenshots for more informations Edited September 8, 2013 by WiaXi (see edit history) Link to comment Share on other sites More sharing options...
codochi Posted September 14, 2013 Share Posted September 14, 2013 Hi, I've slightly modified the Home Featured module to include the randomised option for folks that don't wish to modify the php code and also make it easier to disable the random selection if required. In the configure option for the home featured module I've add an option to select the amount of products to randomly pick from. If you set this to say 100, you featured products page will grab the first 100 products from your home category, shuffle them up and then pick out the amount of products that you have set to be shown. To easily replace you existing module, simply go into the admin area, select the modules tab, locate the existing Home Featured module and select delete. You then select Add a new module, click the browse button and point to the homefeatured.zip file that you have download (homefeatured.zip). Install it by clicking install and then click configure. In the configuration simply set the amount of products you wish to be displayed on the featured area as usual and then set the amount of products you wish to randomly pick from. If you set this to 0 then the random feature will be disabled and you will be back to the standard functionality of the original Home Featured module. Hope this helps... Thank you very much. Nice Guy!!! Link to comment Share on other sites More sharing options...
Kasimir61 Posted November 1, 2013 Share Posted November 1, 2013 I have one other Problem... If i use the Cache System, it will not refresh random - only i delete Smarty Cache by Hand. Is there a Way to avoid this random Function from cache? regards Sven Link to comment Share on other sites More sharing options...
vekia Posted November 1, 2013 Share Posted November 1, 2013 just don't use cache for homefeatured module, you can modify .php file and remove cache functions Link to comment Share on other sites More sharing options...
vinzter Posted November 20, 2013 Share Posted November 20, 2013 just don't use cache for homefeatured module, you can modify .php file and remove cache functions Hi Vekia, Can you tell me how to disable cache functions for just this module ? Thanks Link to comment Share on other sites More sharing options...
vekia Posted November 20, 2013 Share Posted November 20, 2013 remove all $this->_clearCache('homefeatured.tpl'); instances from .php file also remove it from hookDisplayHome($params) function: if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))){ } Link to comment Share on other sites More sharing options...
kakalxlax Posted November 27, 2013 Share Posted November 27, 2013 hi, would it be possible to randomize, for example the "block new products" or "last viewed" ? (adding this code in those modules result in errors) V 1.5.4 Link to comment Share on other sites More sharing options...
kkoottt Posted December 3, 2013 Share Posted December 3, 2013 I uploaded the module, but it does not show anywhere. It shows the module was uploaded successfully, but it does not appear in the list. What should i do? i am using 1.5 thx Link to comment Share on other sites More sharing options...
vekia Posted December 4, 2013 Share Posted December 4, 2013 what module file you uploaded exactly? Link to comment Share on other sites More sharing options...
darktower777 Posted December 19, 2013 Share Posted December 19, 2013 Hello, I would get random products within categories.I use prestashop version 1.4.10 and I do not work to change the code in the productcategory.php file (which I see if it works in other versions):$ categoryProducts = $ category-> getProducts (intval ($ params ['cookie'] -> id_lang), 1, 100);if ($ categoryProducts) {shuffle ($ categoryProducts);array_splice ($ categoryProducts, ($ nb $ nb: 10));}I would comment that I temporarily deleted productcategory.php and continues to show me the list. It's as if the file had nothing to do.Where I can be wrong?Greetings and thanks. (and sorry for my english google) Link to comment Share on other sites More sharing options...
adrianpasita Posted February 11, 2014 Share Posted February 11, 2014 (edited) remove all $this->_clearCache('homefeatured.tpl'); instances from .php file also remove it from hookDisplayHome($params) function: if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))){ } $this->_clearCache('homefeatured.tpl'); this apears in many lines. wich one to remove? and from the hook, wich line also? thanks. 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'); } } Edited February 11, 2014 by adrianpasita (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted February 11, 2014 Share Posted February 11, 2014 you have to remove it from all available places in module php file Link to comment Share on other sites More sharing options...
adrianpasita Posted February 11, 2014 Share Posted February 11, 2014 you have to remove it from all available places in module php file still not working. I give up! I”ve tried all this solution from this forum. I use PS 1.5.6.2. Link to comment Share on other sites More sharing options...
vekia Posted February 11, 2014 Share Posted February 11, 2014 if you use 1.5.6.2 you don't have to remove this code because prestashop 1.5.6.2 supports cache for modules Link to comment Share on other sites More sharing options...
IgorOsnitsky Posted February 12, 2014 Share Posted February 12, 2014 Your modified "homefeatured module" works for me (1.5.6.0) , many thanx for Your solution, gngnet ! Link to comment Share on other sites More sharing options...
b22c Posted February 13, 2014 Share Posted February 13, 2014 (edited) Between (bottom): $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); $this->smarty->assign(array(Add: $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100); if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); }It'll be: $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(That's all Works on 1.5.4.1. Thanks Edited February 13, 2014 by b22c (see edit history) Link to comment Share on other sites More sharing options...
joaocoelho Posted February 19, 2014 Share Posted February 19, 2014 I can't put running on 1.5.6.2 any help? Link to comment Share on other sites More sharing options...
adrianpasita Posted February 19, 2014 Share Posted February 19, 2014 I can't put running on 1.5.6.2 any help? I have the same problem. I tried all the solution on this forum and it dosent work. Link to comment Share on other sites More sharing options...
vekia Posted February 20, 2014 Share Posted February 20, 2014 method two posts above should work for you. make sure that after changes you cleared cache and force compiled theme, without this you will not see changes 1 Link to comment Share on other sites More sharing options...
joaocoelho Posted February 20, 2014 Share Posted February 20, 2014 Cache cleared; theme with force compiled. Same result, not working. Link to comment Share on other sites More sharing options...
vekia Posted February 20, 2014 Share Posted February 20, 2014 strange, you've got enough products attached to home category? Link to comment Share on other sites More sharing options...
adrianpasita Posted February 20, 2014 Share Posted February 20, 2014 strange, you've got enough products attached to home category? All my products are in different subcategories. There are checked on Home also, but i setted Default category the subcategorie. Is that the problem? Link to comment Share on other sites More sharing options...
vekia Posted February 21, 2014 Share Posted February 21, 2014 homefeatured module uses products associated with "home" category if you want to dispaly products in featured block - you have to associate products with this category. Link to comment Share on other sites More sharing options...
vmiloykov Posted March 9, 2014 Share Posted March 9, 2014 homefeatured module uses products associated with "home" category if you want to dispaly products in featured block - you have to associate products with this category. How this can be done? Link to comment Share on other sites More sharing options...
vekia Posted March 9, 2014 Share Posted March 9, 2014 go to product edit page, and associate it with "home" category Link to comment Share on other sites More sharing options...
lalala lululu Posted March 9, 2014 Share Posted March 9, 2014 (edited) if you use 1.5.6.2 you don't have to remove this code because prestashop 1.5.6.2 supports cache for modules Hello im using 1.5.6.2. im wondering how to disable caching for this module, to get fresh list of featured products for every refresh of page. Or any oher way to achieve this (if possible- cache 100 products and then pick random 7pcs every time page is reloaded) Thank you <3 www.prosperk.cz Edited March 9, 2014 by lalala lululu (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 you can remove cache only with modification of module php file, there is no other way, unfortunately. inside homefeatured.php file you can find code like: 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')); } instead of this code, use this one: 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"); $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...
lalala lululu Posted March 10, 2014 Share Posted March 10, 2014 you can remove cache only with modification of module php file, there is no other way, unfortunately. inside homefeatured.php file you can find code like: 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')); } instead of this code, use this one: 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"); $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'); } Thank you for your reply. Unfortunately i already made this before i ask... but module still works like it uses cache... shuffeling works good, but i see change only after reloading my cache. I dont understand why. Im sure i removed the "isCached" condition as you said. prosperk.cz here you can see in block "Vybrali jsme pro Vás". Thank you again Vekia. Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 and removed it also from return $this->display(__FILE__, 'homefeatured.tpl'); ? Link to comment Share on other sites More sharing options...
lalala lululu Posted March 10, 2014 Share Posted March 10, 2014 and removed it also from return $this->display(__FILE__, 'homefeatured.tpl'); ? Ah thats it! Thank you for your dumb resistant patience. Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 )so, now after changes, it works as it should ? (God, i hope so 1 Link to comment Share on other sites More sharing options...
lalala lululu Posted March 10, 2014 Share Posted March 10, 2014 Yes Vekia. Nice and clean:) Thank you and respect for your great support Link to comment Share on other sites More sharing options...
joaocoelho Posted March 10, 2014 Share Posted March 10, 2014 and removed it also from return $this->display(__FILE__, 'homefeatured.tpl'); ? Can you be more specific please? Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 by default code looks like: return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); it's necessary to change it to return $this->display(__FILE__, 'homefeatured.tpl'); i removed this part of code: , $this->getCacheId('homefeatured') it's a part related to cache, so it's necessary to remove it. 1 Link to comment Share on other sites More sharing options...
b22c Posted March 14, 2014 Share Posted March 14, 2014 Changing the code work for me and i use it for about 1 month but i note that some of my products were never displayed. If i want to display lets say 28 products ramdomly i just check the category home, or i can displayed ramdomly by category... Very happy with this module... I note that some products that werent displayed with changing the code are now displayed... 1 Link to comment Share on other sites More sharing options...
Cassiano Aquino Posted March 16, 2014 Share Posted March 16, 2014 (edited) Using PrestaShop Legend examples, my prestashop 1.5.6.2 is working as well. Thanks a lot 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"); 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'); } Sorry my bad english. Edited March 16, 2014 by Cassiano Aquino (see edit history) 3 Link to comment Share on other sites More sharing options...
wjq588jk Posted March 16, 2014 Share Posted March 16, 2014 Using PrestaShop Legend examples, my prestashop 1.5.6.2 is working as well. Thanks a lot 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"); 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'); } Sorry my bad english. Thank you very much. This is the correct way for the ps1.5.6.2 1 Link to comment Share on other sites More sharing options...
designerspain Posted March 16, 2014 Share Posted March 16, 2014 Thank you very much. This is the correct way for the ps1.5.6.2 Thanks, It works in 1.5.6.2 But only random the first 8 articles... How can I tell the module to take all items in home to show them randomly? Link to comment Share on other sites More sharing options...
vekia Posted March 16, 2014 Share Posted March 16, 2014 Thanks, It works in 1.5.6.2 But only random the first 8 articles... How can I tell the module to take all items in home to show them randomly? change line: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); to: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,null,true,true); 1 Link to comment Share on other sites More sharing options...
designerspain Posted March 17, 2014 Share Posted March 17, 2014 change line: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); to: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,null,true,true); Hi. Thanks for the help. But it doesn´t work. it takes all the articles in home and random them but only show 1 in main page. Link to comment Share on other sites More sharing options...
Law2602 Posted March 20, 2014 Share Posted March 20, 2014 Hi. Thanks for the help. But it doesn´t work. it takes all the articles in home and random them but only show 1 in main page. I have the same problem as designerspain. Although its on 1.6 I presume that I can use the same solution as he would get Am following Link to comment Share on other sites More sharing options...
suxberger Posted March 21, 2014 Share Posted March 21, 2014 I'm having the same problem, after making changes products are random, but only one. Link to comment Share on other sites More sharing options...
djbuio Posted March 21, 2014 Share Posted March 21, 2014 there's a solution for PS 1.6.0.5 too?....... Link to comment Share on other sites More sharing options...
designerspain Posted March 26, 2014 Share Posted March 26, 2014 I think no one knows how to solve this. Is there any way to show the new items in home module? I think we all want to not be shown always the same products. So if we can´t random them if it is possible to make the module show the new ones can be a good solution too. Link to comment Share on other sites More sharing options...
fosg2000 Posted March 27, 2014 Share Posted March 27, 2014 there's a solution for PS 1.6.0.5 too? Link to comment Share on other sites More sharing options...
vekia Posted March 27, 2014 Share Posted March 27, 2014 it's neessary to remove caching from this module (all caching functions) and of course to change this: $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); to function already mentioned somewhere above 1 Link to comment Share on other sites More sharing options...
Coancas Posted March 28, 2014 Share Posted March 28, 2014 this worked for me $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), NULL,NULL,false,true,true,($nb ? $nb : 50)); on 1.5.6.2 1 Link to comment Share on other sites More sharing options...
fosg2000 Posted March 28, 2014 Share Posted March 28, 2014 any clues for 1.6 ? for : NEW ARRIVALS POPULAR PRODUCTS BEST SELLERS Link to comment Share on other sites More sharing options...
Grindelf Posted April 13, 2014 Share Posted April 13, 2014 worked for me with this code: public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT')); $shuffle = (Configuration::get('HOME_FEATURED_RNBR')) ? true:false; $rnb = ($shuffle) ? (int)Configuration::get('HOME_FEATURED_RNBR'):(int)Configuration::get('HOME_FEATURED_NBR'); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($rnb ? $rnb : 10), "position",NULL,NULL,true,true,($nb ? $nb : 50)); 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('home'), )); ty FOR ALL POSTS Link to comment Share on other sites More sharing options...
Totti Posted April 14, 2014 Share Posted April 14, 2014 worked for me with this code: public function hookDisplayHome($params) { $category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT')); $shuffle = (Configuration::get('HOME_FEATURED_RNBR')) ? true:false; $rnb = ($shuffle) ? (int)Configuration::get('HOME_FEATURED_RNBR'):(int)Configuration::get('HOME_FEATURED_NBR'); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($rnb ? $rnb : 10), "position",NULL,NULL,true,true,($nb ? $nb : 50)); 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('home'), )); ty FOR ALL POSTS Work in Ps 1.6 ? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 14, 2014 Share Posted May 14, 2014 it's neessary to remove caching from this module (all caching functions) and of course to change this: $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); to function already mentioned somewhere above Hi Vekia! I try to random product display in my shop, presta 1.5.6.1, i have try your code http://mypresta.eu/en/art/tips-and-tricks/how-to-display-products-randomly-in-prestashop-home-featured-module.html but don't work. Do you can help me? i don't found the error, my homefeatured.php: 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){ $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)); 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'); } 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 14, 2014 Share Posted May 14, 2014 but don't work. what's going on? white page? some errors? Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 14, 2014 Share Posted May 14, 2014 No, no errors, no white page, but on featured page, products are always the same in same position, they don't change Link to comment Share on other sites More sharing options...
devoox Posted May 15, 2014 Share Posted May 15, 2014 Hi, i did a tuto in French for explain how to make the homefeatured modules showing random products. http://www.netick.fr/blog/prestashop-module-produits-phares.html Peace of cake Link to comment Share on other sites More sharing options...
cicciotargatona Posted May 15, 2014 Share Posted May 15, 2014 Hi, i did a tuto in French for explain how to make the homefeatured modules showing random products. http://www.netick.fr/blog/prestashop-module-produits-phares.html Peace of cake Bonsoir devooxn merci pour la reponse. J'ai prestashop 1.5.6.1, j'ai essaie ton code mais ca ne marche pas... tu sais quoi faire pour ma version de pretashop? Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 Finally I read one and other time the whole topic... Im lost Im using 1.6.0.5.. I need to random products from all my categories in homefeatured module... some help pls.. Link to comment Share on other sites More sharing options...
vekia Posted May 16, 2014 Share Posted May 16, 2014 Finally I read one and other time the whole topic... Im lost Im using 1.6.0.5.. I need to random products from all my categories in homefeatured module... some help pls.. do you used some solutions provided here? or just read only? Link to comment Share on other sites More sharing options...
amcm112 Posted May 16, 2014 Share Posted May 16, 2014 do you used some solutions provided here? or just read only? I ever read almost all... then when I open the homefeatured.php I didnt find where to place or replace any code.. I mind is becasuse Im with 1.6.0.5 ...? the code I open do not have any similar to the examples shown here... I try some but nothing happend.. Link to comment Share on other sites More sharing options...
vekia Posted May 16, 2014 Share Posted May 16, 2014 public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId())) { $this->_cacheProducts(); $this->smarty->assign( array( 'products' => HomeFeatured::$cache_products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), ) ); } return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId()); } change it to: public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId())) { $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', $this->getCacheId()); } 2 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