St055 Posted March 20, 2014 Share Posted March 20, 2014 Hello, How to have the featured product dispolayed randomly on home?... Ive opened homefeatured.php but all is in cache, I don't know how to do that... Any idea please? Link to comment Share on other sites More sharing options...
vybornak Posted March 20, 2014 Share Posted March 20, 2014 on homefeutured.php about row 113 you will find something like this HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); Coment this text and paste this HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, 100, 'position'); if (HomeFeatured::$cache_products) { shuffle(HomeFeatured::$cache_products); array_splice(HomeFeatured::$cache_products, ($nb ? $nb : 8)); 2 Link to comment Share on other sites More sharing options...
St055 Posted March 20, 2014 Author Share Posted March 20, 2014 Thanks! But sorry, doesn't work... The products are still the same, and same order... :-( Link to comment Share on other sites More sharing options...
Daniel - PrestaBR Posted March 22, 2014 Share Posted March 22, 2014 Up. No luck over here as well. Link to comment Share on other sites More sharing options...
mendi_xtv Posted March 22, 2014 Share Posted March 22, 2014 (edited) Hi Change that: domain/module/homefeatured/homefeatured.php ----------------------------------------- OLD: 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()); } ---------------------------------------------------------------------------------------------- NEW: 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'); } -------------------------------------------- Edited March 23, 2014 by Daniel - PrestaBR (see edit history) 8 Link to comment Share on other sites More sharing options...
djbuio Posted March 22, 2014 Share Posted March 22, 2014 for me it works! Great job. thanx Link to comment Share on other sites More sharing options...
vekia Posted March 23, 2014 Share Posted March 23, 2014 everything is because of caching. this module uses caching so it will show new products ( by new i mean randomly) only with force compile and without cache. this is why it's necessary to remove caching functions 1 Link to comment Share on other sites More sharing options...
St055 Posted March 23, 2014 Author Share Posted March 23, 2014 Yes! It works; thanks! :-) Link to comment Share on other sites More sharing options...
vmarkovic Posted April 21, 2014 Share Posted April 21, 2014 (edited) Hi Guys, I tried mendi_xtv's method but only few of my home category products are displayed with random position. See here: http://hejkupi.me/test/ Edited April 21, 2014 by vmarkovic (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 use this: $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true); 1 Link to comment Share on other sites More sharing options...
vmarkovic Posted April 21, 2014 Share Posted April 21, 2014 use this: $category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true); Thanks Vekia, I will try this as soon as I am on my PC. Should I edit stock homefeatured.php or this edited one? Regards, Vedran Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 you can edit actual file that you already changed Link to comment Share on other sites More sharing options...
vmarkovic Posted April 21, 2014 Share Posted April 21, 2014 Hi Vekia, Thanks for you reply.I just replaced the following line in my edited homefeatured.php $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); With yours $category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true); But then I get following error:Notice: Undefined variable: category in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 129Fatal error: Call to a member function getProducts() on a non-object in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 129 This is my edited code: public function hookDisplayHome($params){ $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);$nb = (int)(Configuration::get('HOME_FEATURED_NBR')); /*$products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10));*/ $products = $category->getProducts((int)Context::getContext()->language->id, 7, ($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'); } What am I doing wrong, did I edited the right line? Thanks in advance.Regards,Vedran Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 you have to use code that i suggested instead of: $products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb); Link to comment Share on other sites More sharing options...
vmarkovic Posted April 21, 2014 Share Posted April 21, 2014 (edited) you have to use code that i suggested instead of: $products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb); Hi Vekia, I just did that, but same 10-15 products are randomly displayed when refreshed (I have more than 15 products in my home category). I Also have this modification on my live 1.5 site which is working great. Edit: Actually, I got an following error: Warning: shuffle() expects parameter 1 to be array, null given in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 134 And no homefeaured products, just this message: No featured products at this time. Here is my 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));*/ $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('home_default'), )); return $this->display(__FILE__, 'homefeatured.tpl'); } My test site: http://hejkupi.me/test Regards, Vedran Edited April 21, 2014 by vmarkovic (see edit history) Link to comment Share on other sites More sharing options...
fosg2000 Posted April 29, 2014 Share Posted April 29, 2014 works great for me. but sometimes displays items out of stock, theres any way to sort just with products in stock ? www.bostonrecycling.net Link to comment Share on other sites More sharing options...
vekia Posted April 29, 2014 Share Posted April 29, 2014 $category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true); to $products=$category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true); Link to comment Share on other sites More sharing options...
fosg2000 Posted April 29, 2014 Share Posted April 29, 2014 That was quick ! Ill try in a few Thanks Link to comment Share on other sites More sharing options...
fosg2000 Posted April 30, 2014 Share Posted April 30, 2014 just try, but dont work !!! www.bostonrecycling.net Link to comment Share on other sites More sharing options...
vekia Posted April 30, 2014 Share Posted April 30, 2014 sorry for misunderstanding but my post was to vmarkovic. in your case it's necessary to modify core function getProducts, but in this case it will affect also other part of shop where the product listings are visible Link to comment Share on other sites More sharing options...
Kurmus Posted May 11, 2014 Share Posted May 11, 2014 mendi_xtv its great 1 Link to comment Share on other sites More sharing options...
[email protected] Posted May 16, 2014 Share Posted May 16, 2014 (edited) Thanks mendi_xtv for your solution my website started working fabulously Edited May 17, 2014 by [email protected] (see edit history) Link to comment Share on other sites More sharing options...
iGiorgis Posted May 28, 2014 Share Posted May 28, 2014 (edited) i try the code from mendi_xtv but i lose the ribbons I want to show randomly all my "home" products but to show 8 or 12 at home page! how i do that? Edited May 28, 2014 by iGiorgis (see edit history) Link to comment Share on other sites More sharing options...
Xzelot Posted June 6, 2014 Share Posted June 6, 2014 I think a " } " was missed and that's why is not working...i put at the end of the line the } and works for my HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, 100, 'position'); if (HomeFeatured::$cache_products) { shuffle(HomeFeatured::$cache_products); array_splice(HomeFeatured::$cache_products, ($nb ? $nb : 8)); } Look the code, there is an if. Then Clean the Cache from the store, and it's work!, Link to comment Share on other sites More sharing options...
mike117 Posted June 16, 2014 Share Posted June 16, 2014 (edited) The changes only randomise the same 20 products for my store, i want to be able to get a total random selection of products not just move around the same products. www.w2g.co.uk thanks in advance for any help lots of posts are confusing does anyone have simpled down version for a total random selection of products from you entire inventory? Edited June 16, 2014 by mike117 (see edit history) Link to comment Share on other sites More sharing options...
guadalupesg Posted July 6, 2014 Share Posted July 6, 2014 Thanks, mendi_xtv, I´m using your code and it works OK. Great! Link to comment Share on other sites More sharing options...
AZAHARAFUENGIROLA Posted July 10, 2014 Share Posted July 10, 2014 For me doesn't work anymore... it shows always the same products... Link to comment Share on other sites More sharing options...
guadalupesg Posted July 11, 2014 Share Posted July 11, 2014 Just change this function: 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());} for this 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'); } Replace the whole function, and it works. Link to comment Share on other sites More sharing options...
AZAHARAFUENGIROLA Posted July 11, 2014 Share Posted July 11, 2014 Thanks but, two days ago works perfectly, but now not works... I replace again but is the same.... Link to comment Share on other sites More sharing options...
vmarkovic Posted July 14, 2014 Share Posted July 14, 2014 (edited) Thanks but, two days ago works perfectly, but now not works... I replace again but is the same.... Hi, Did you updated Top sellers module in those 2 days? Regards, Vedran Edited July 14, 2014 by vmarkovic (see edit history) Link to comment Share on other sites More sharing options...
AZAHARAFUENGIROLA Posted July 15, 2014 Share Posted July 15, 2014 I think no... I only upload my template Link to comment Share on other sites More sharing options...
webonmaster Posted August 16, 2014 Share Posted August 16, 2014 Hi: How to random on 1.6.0.9 related products?? Thanks. Link to comment Share on other sites More sharing options...
vmarkovic Posted August 18, 2014 Share Posted August 18, 2014 Hi webonmaster,You have to edit /public_html/modules/homefeatured/homefeatured.php.Replace this part: 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()); } with 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 : 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'); } I just tried this on my 1.6.0.9 - it works.Regards, Vedran 1 Link to comment Share on other sites More sharing options...
webonmaster Posted August 18, 2014 Share Posted August 18, 2014 thanks vmarkovic I have that part solved with the same code.the one I need is for thumbnails 30 other products in the same category.Also many thanks and sorry for my English. Link to comment Share on other sites More sharing options...
vmarkovic Posted August 18, 2014 Share Posted August 18, 2014 Hi webonmaster, Sorry didnt catched that. Interesting question though, would like to know that myself. Regards, Vedran Link to comment Share on other sites More sharing options...
Totti Posted August 19, 2014 Share Posted August 19, 2014 It works.is possible via a query to show only the products in stock ? Link to comment Share on other sites More sharing options...
jirikcz Posted August 22, 2014 Share Posted August 22, 2014 (edited) Hi Verdan, I try your edit but it works only if I switch between New arrivals and Popular. But I have Popular on 1st switch and New arrivals on 2nd switch on my homepage. When I come to my website I can see on both switches (Popular and New arrivals) the same products. Your edit take effect after I switch Popular -> News and back to Popular and take effect only once. I have to refresh my website, switch Popular -> New arrivals and back and after this product random. Do I something wrong? Thanks for help. jirikcz Hi webonmaster,You have to edit /public_html/modules/homefeatured/homefeatured.php.Replace this part: 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()); } with 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 : 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'); } I just tried this on my 1.6.0.9 - it works.Regards, Vedran Edited August 25, 2014 by jirikcz (see edit history) Link to comment Share on other sites More sharing options...
Robert79 Posted August 23, 2014 Share Posted August 23, 2014 Działa Dziękuję Link to comment Share on other sites More sharing options...
vmarkovic Posted August 23, 2014 Share Posted August 23, 2014 Hi Verdan, I try your edit but it works only if I switch between New arrivals and Popular. But I have Popular on 1st switch and New arrivals on 2nd switch on my homepage. When I come to my website I can see on both switches (Popular and New arrivals) the same products. Your edit take effect after I switch Popular -> News and back to Popular and take effect only once. I have to refresh my website, switch Popular -> New arrivals and back and after this product random. You can see it on my website at http://76345.w45.wedos.ws/en/ . Do I something wrong? Thanks for help. jirikcz Hi jirikcz, I just copy/pasted code and instructions from this topic so I am not sure are you doing something wrong. Regards, Vedrav Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 3, 2014 Share Posted September 3, 2014 (edited) I'm using with success mendi_xtv, but I have a question, It's possible to show random product taken from all products at catalog instead on only products assigned to home category? Edited September 25, 2014 by DARKF3D3 (see edit history) 1 Link to comment Share on other sites More sharing options...
junnecito Posted September 12, 2014 Share Posted September 12, 2014 Hi Vedrav: Works fine, thanks a lot. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 25, 2014 Share Posted September 25, 2014 I'm using with success mendi_xtv, but I have a question, It's possible to show random product taken from all products at catalog instead on only products assigned to home category? No one know I can do that? Link to comment Share on other sites More sharing options...
prestatuga Posted September 25, 2014 Share Posted September 25, 2014 Hi DARF3D3 You have to change ".../modules/homefeatured/homefeatured.php" at line 107 replace this: public function _cacheProducts() { if (!isset(HomeFeatured::$cache_products)) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); } if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products)) return false; } with this: public function _cacheProducts() { if (!isset(HomeFeatured::$cache_products)) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); /*HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');*/ HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), NULL,NULL,false,true,true,($nb ? $nb : 100)); } if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products)) return false; } Regards, prestatuga 1 Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 25, 2014 Share Posted September 25, 2014 Hi prestatuga, I copied your code into the homefeatured.php file but to me the products showed seem to be the same as before, I countinue seeing only products assigned to home category. Link to comment Share on other sites More sharing options...
prestatuga Posted September 26, 2014 Share Posted September 26, 2014 Hi DARF3D3 Sorry for my mistake and the incomplete information.In my shop I added all products to the home category besides having its own main category.In this store have less than 100 items. If necessary, you can increase the number of random items.This is not the most elegant solution, but it was the only one that got it working.I do not have many products and in my case it was easy. In a very large store will be painful to edit all items. best regards, Prestatuga Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 27, 2014 Share Posted September 27, 2014 Ok now it's clear, thanks Prestatuga. Infact I was looking for something that can show random products also in not assigned to home category because I have a large amount of products at catalogue. Link to comment Share on other sites More sharing options...
Jhony Ranger Posted September 28, 2014 Share Posted September 28, 2014 In ps1.6, the new update version of module is done. Regards. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 28, 2014 Share Posted September 28, 2014 Hi Jhonny, what do you mean with your phrase? I'm sorry but m English it's not the best. Link to comment Share on other sites More sharing options...
Jhony Ranger Posted September 29, 2014 Share Posted September 29, 2014 Hi Jhonny, what do you mean with your phrase? I'm sorry but m English it's not the best. The new version of the module, including the random option. (La nueva versión del módulo, incluye la opción "aleatorios"). My English is very bad, sorry. Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 29, 2014 Share Posted September 29, 2014 Do you know the version number? Mine it's the 1.5 and i don't see the random option and PS doesn't show the message of new update available. Link to comment Share on other sites More sharing options...
Jhony Ranger Posted September 29, 2014 Share Posted September 29, 2014 Do you know the version number? Mine it's the 1.5 and i don't see the random option and PS doesn't show the message of new update available. The new version is available in ps1.6 Link to comment Share on other sites More sharing options...
DARKF3D3 Posted September 29, 2014 Share Posted September 29, 2014 Yes I have PS1.6 and the last version of the module i find is the 1.5 but i don't see the random product feature. Link to comment Share on other sites More sharing options...
fosg2000 Posted September 29, 2014 Share Posted September 29, 2014 can someone please update the new hole homefeatured.php file, for just replace it thanks Link to comment Share on other sites More sharing options...
Jhony Ranger Posted September 29, 2014 Share Posted September 29, 2014 can someone please update the new hole homefeatured.php file, for just replace it thanks if (!defined('_PS_VERSION_')) exit; class HomeFeatured extends Module { protected static $cache_products; public function __construct() { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; $this->version = '1.6'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Featured products on the homepage'); $this->description = $this->l('Displays featured products in the central column of your homepage.'); } public function install() { $this->_clearCache('*'); Configuration::updateValue('HOME_FEATURED_NBR', 8); Configuration::updateValue('HOME_FEATURED_CAT', (int)Context::getContext()->shop->getCategory()); Configuration::updateValue('HOME_FEATURED_RANDOMIZE', false); if (!parent::install() || !$this->registerHook('header') || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('deleteproduct') || !$this->registerHook('categoryUpdate') || !$this->registerHook('displayHomeTab') || !$this->registerHook('displayHomeTabContent') ) return false; return true; } public function uninstall() { $this->_clearCache('*'); return parent::uninstall(); } public function getContent() { $output = ''; $errors = array(); if (Tools::isSubmit('submitHomeFeatured')) { $nbr = Tools::getValue('HOME_FEATURED_NBR'); if (!Validate::isInt($nbr) || $nbr <= 0) $errors[] = $this->l('The number of products is invalid. Please enter a positive number.'); $cat = Tools::getValue('HOME_FEATURED_CAT'); if (!Validate::isInt($cat) || $cat <= 0) $errors[] = $this->l('The category ID is invalid. Please choose an existing category ID.'); $rand = Tools::getValue('HOME_FEATURED_RANDOMIZE'); if (!Validate::isBool($rand)) $errors[] = $this->l('Invalid value for the "randomize" flag.'); if (isset($errors) && count($errors)) $output = $this->displayError(implode('<br />', $errors)); else { Configuration::updateValue('HOME_FEATURED_NBR', (int)$nbr); Configuration::updateValue('HOME_FEATURED_CAT', (int)$cat); Configuration::updateValue('HOME_FEATURED_RANDOMIZE', (bool)$rand); Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('homefeatured.tpl')); $output = $this->displayConfirmation($this->l('Your settings have been updated.')); } } return $output.$this->renderForm(); } public function hookDisplayHeader($params) { $this->hookHeader($params); } public function hookHeader($params) { if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'index') $this->context->controller->addCSS(_THEME_CSS_DIR_.'product_list.css'); $this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all'); } public function _cacheProducts() { if (!isset(HomeFeatured::$cache_products)) { $category = new Category((int)Configuration::get('HOME_FEATURED_CAT'), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); if (Configuration::get('HOME_FEATURED_RANDOMIZE')) HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8)); else HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position'); } if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products)) return false; } public function hookDisplayHomeTab($params) { if (!$this->isCached('tab.tpl', $this->getCacheId('homefeatured-tab'))) $this->_cacheProducts(); return $this->display(__FILE__, 'tab.tpl', $this->getCacheId('homefeatured-tab')); } 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()); } public function hookDisplayHomeTabContent($params) { return $this->hookDisplayHome($params); } public function hookAddProduct($params) { $this->_clearCache('*'); } public function hookUpdateProduct($params) { $this->_clearCache('*'); } public function hookDeleteProduct($params) { $this->_clearCache('*'); } public function hookCategoryUpdate($params) { $this->_clearCache('*'); } public function _clearCache($template, $cache_id = NULL, $compile_id = NULL) { parent::_clearCache('homefeatured.tpl'); parent::_clearCache('tab.tpl', 'homefeatured-tab'); } public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'description' => $this->l('To add products to your homepage, simply add them to the corresponding product category (default: "Home").'), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Number of products to be displayed'), 'name' => 'HOME_FEATURED_NBR', 'class' => 'fixed-width-xs', 'desc' => $this->l('Set the number of products that you would like to display on homepage (default: 8).'), ), array( 'type' => 'text', 'label' => $this->l('Category from which to pick products to be displayed'), 'name' => 'HOME_FEATURED_CAT', 'class' => 'fixed-width-xs', 'desc' => $this->l('Choose the category ID of the products that you would like to display on homepage (default: 2 for "Home").'), ), array( 'type' => 'switch', 'label' => $this->l('Randomly display featured products'), 'name' => 'HOME_FEATURED_RANDOMIZE', 'class' => 'fixed-width-xs', 'desc' => $this->l('Enable if you wish the products to be displayed randomly (default: no).'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('No') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $this->fields_form = array(); $helper->id = (int)Tools::getValue('id_carrier'); $helper->identifier = $this->identifier; $helper->submit_action = 'submitHomeFeatured'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } public function getConfigFieldsValues() { return array( 'HOME_FEATURED_NBR' => Tools::getValue('HOME_FEATURED_NBR', (int)Configuration::get('HOME_FEATURED_NBR')), 'HOME_FEATURED_CAT' => Tools::getValue('HOME_FEATURED_CAT', (int)Configuration::get('HOME_FEATURED_CAT')), 'HOME_FEATURED_RANDOMIZE' => Tools::getValue('HOME_FEATURED_RANDOMIZE', (bool)Configuration::get('HOME_FEATURED_RANDOMIZE')), ); } } 1 Link to comment Share on other sites More sharing options...
fosg2000 Posted September 29, 2014 Share Posted September 29, 2014 Thanks ! just replace it, but when refresh the store shows the same product check http://www.bostonrecycling.net/ thanks Link to comment Share on other sites More sharing options...
farruk0 Posted September 30, 2014 Share Posted September 30, 2014 Hi, anyone knows how to hide out of stocks products? Thanks Link to comment Share on other sites More sharing options...
fosg2000 Posted September 30, 2014 Share Posted September 30, 2014 Thanks ! just replace it, but when refresh the store shows the same product check http://www.bostonrecycling.net/ thanks any news ??? Link to comment Share on other sites More sharing options...
deepxfan Posted October 6, 2014 Share Posted October 6, 2014 Thank you Vekia, It worked for me! Link to comment Share on other sites More sharing options...
DARKF3D3 Posted October 10, 2014 Share Posted October 10, 2014 I solved all my problem using this module:http://addons.prestashop.com/it/funzionalita-front-office-moduli-prestashop/3518-random-home-featured-products.html Radom products taken from all products at catalogue + possibility to show only available products. Link to comment Share on other sites More sharing options...
colnago5 Posted October 15, 2014 Share Posted October 15, 2014 Thanks a lot¡¡¡¡ Link to comment Share on other sites More sharing options...
ars3n Posted November 18, 2014 Share Posted November 18, 2014 Awesome post. Thanks! Link to comment Share on other sites More sharing options...
zeki893 Posted February 10, 2015 Share Posted February 10, 2015 (edited) Why was the method originally date_add then changed to position? I am using date_add but after I saw this post using position, I'm trying to understand getProducts different orders. if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') $order_by_prefix = 'p'; else if ($order_by == 'name') $order_by_prefix = 'pl'; else if ($order_by == 'position') $order_by_prefix = 'c'; p, pl, and c. Can someone explain please? TIA Edited February 10, 2015 by zeki893 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts