vanillafrog Posted September 22, 2012 Share Posted September 22, 2012 (edited) Hi all! I want to change the homefeatured module so that it doesn't show products from just "home" category, but "Accessories" category. I've looked around the forums and found out so far that we have to change this line in homefeatured.php, 1 bring the ID of the category: $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); to $products = $category->getProducts((int)Context::getContext()->language->id, 37, ($nb ? $nb : 10)); It's not working for me though. When I change it to 37, it states "no featured products", when I already have 2 products in Accessories. Am I missing something in 1.5? Thank you in advance!! Edited September 23, 2012 by vanillafrog (see edit history) Link to comment Share on other sites More sharing options...
Metang Posted September 26, 2012 Share Posted September 26, 2012 same question here. someone please help Link to comment Share on other sites More sharing options...
Médéric Posted September 26, 2012 Share Posted September 26, 2012 hi you can change this line in the .php just before $products: $category = new Category(ID_OF_YOUR_CATEGORY, (int)Context::getContext()->language->id); woks for me with 1.5 regards 2 Link to comment Share on other sites More sharing options...
vanillafrog Posted September 27, 2012 Author Share Posted September 27, 2012 THANK YOU THANK YOU THANK YOU Mederic!!! Tried it and it works! No need to change the category number at $products. Just changing the line above will do. 1 Link to comment Share on other sites More sharing options...
patrizia.vergassola Posted January 21, 2013 Share Posted January 21, 2013 hi you can change this line in the .php just before $products: $category = new Category(ID_OF_YOUR_CATEGORY, (int)Context::getContext()->language->id); woks for me with 1.5 regards And if I wanna show products from all the categories? Thanks! Patrizia Link to comment Share on other sites More sharing options...
aljon1234 Posted February 27, 2014 Share Posted February 27, 2014 How can i combine 2 categories to show up? for example $category = new Category(ID_OF_YOUR_CATEGORY1, (int)Context::getContext()->language->id); + $category = new Category(ID_OF_YOUR_CATEGORY2, (int)Context::getContext()->language->id); Link to comment Share on other sites More sharing options...
vekia Posted February 27, 2014 Share Posted February 27, 2014 you can do it in two ways, duplicate categories as a separate variables, then use two foreach loops on these variables in .tpl file. or just you can use array_merge() code to merge two $category1->getProducts() and $category2->getProducts() functions results 1 Link to comment Share on other sites More sharing options...
aljon1234 Posted February 28, 2014 Share Posted February 28, 2014 Thanks Vekia, i used array merge and it work fine with Link to comment Share on other sites More sharing options...
vekia Posted February 28, 2014 Share Posted February 28, 2014 nice i think this is the best option instead of several foreach loops. in addition, we can shuffle() merged variable to products will appear randomly 1 Link to comment Share on other sites More sharing options...
Detelin Markov Posted March 3, 2014 Share Posted March 3, 2014 (edited) Hi, I try patrizia.vergassola way but not working for me presta 1.5.6.2 or i make something wrong? I try to show products from category 5 but still loading default products.. $category = new Category(5, (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, Or can be possible to set up several products that show up instead category? Thanks Edited March 3, 2014 by Detelin Markov (see edit history) Link to comment Share on other sites More sharing options...
aljon1234 Posted March 4, 2014 Share Posted March 4, 2014 Hi, I try patrizia.vergassola way but not working for me presta 1.5.6.2 or i make something wrong? I try to show products from category 5 but still loading default products.. $category = new Category(5, (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8)); $this->smarty->assign(array( 'products' => $products, Or can be possible to set up several products that show up instead category? Thanks Did you check if category 5 really exist? maybe you are calling the wrong id number in the database of the category Link to comment Share on other sites More sharing options...
vekia Posted March 4, 2014 Share Posted March 4, 2014 it can be related to ... cache. homefeatured module uses cache engine (for performance purposes) so after each core change (functions related to products) it's necessary to clear it maybe this is the main problem 1 Link to comment Share on other sites More sharing options...
Detelin Markov Posted March 4, 2014 Share Posted March 4, 2014 After two times clear the cache problem is solved. Just need to clear the cache, thank you! Link to comment Share on other sites More sharing options...
Orhion.ro Posted May 12, 2014 Share Posted May 12, 2014 you can do it in two ways, duplicate categories as a separate variables, then use two foreach loops on these variables in .tpl file. or just you can use array_merge() code to merge two $category1->getProducts() and $category2->getProducts() functions results Hi vekia, Can you give me the exact code for this option? Link to comment Share on other sites More sharing options...
vekia Posted May 12, 2014 Share Posted May 12, 2014 Hi vekia, Can you give me the exact code for this option? here it is: $cat=$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $cat1=$category1->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $products = array_merge($cat,$cat1) ; don't forget to define $category and $category1 objects with categories you want to display. Link to comment Share on other sites More sharing options...
Orhion.ro Posted May 12, 2014 Share Posted May 12, 2014 (edited) this worked for me $category = new Category(8, (int)Context::getContext()->language->id); $category1 = new Category(9, (int)Context::getContext()->language->id); $category2 = new Category(10, (int)Context::getContext()->language->id); $category3 = new Category(11, (int)Context::getContext()->language->id); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); $cat=$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $cat1=$category1->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $cat2=$category2->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $cat3=$category3->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position"); $products = array_merge($cat,$cat1,$cat2,$cat3) ; In the module i set to display 3 products, and on my homepage, it shows 12 products( 3 products x 4 categories selected) Thank you Vekia Edited May 12, 2014 by Orhion.ro (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts