Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Product list filtered by category
 
jmassi
Jr. Member
 
Total Posts:  8
Joined:  2008-10-29
 

I need to create a block that contains the bestsellers products of a specific category.

How can I filter the product collection by category id?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi @jmassi,

Thanks to @Lee Saferite.

In your .phtml file, you’ll read a line of code similar to this:

$_productCollection=$this->getLoadedProductCollection();

Go underneath and ADD the following (where $cat_id corresponds to the id of the product category you want to display):

$cat_id 6// category_id for "specific category"
$_productCollection Mage::getResourceModel('catalog/product_collection')
->
addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));

Let us know how it goes.

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
edmondscommerce
Guru
 
Avatar
Total Posts:  342
Joined:  2008-08-26
 

There is now a new method you will need to use to add category_ids to your collection:

You will need to add this to your collection:

$this->_productCollection->addCategoryIds();

You can Check out more here!

Hope this helps!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top