Jump to content

Changing category of homefeatured in 1.5


Recommended Posts

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 by vanillafrog (see edit history)
Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...

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

  • Like 1
Link to comment
Share on other sites

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 by Detelin Markov (see edit history)
Link to comment
Share on other sites

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

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 :)

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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

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

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 by Orhion.ro (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...