How to get products from a particular category in magento ecommerce

Allbutlost picture Allbutlost · Jan 18, 2009 · Viewed 95k times · Source

I'd like to get a list of random products from the same category as the current product for displaying within the product view - so far all I've dug up is

Magento products by categories

Does anyone know how to do this?

Answer

Josh Pennington picture Josh Pennington · Jun 12, 2011

You basically load up the category, get the Product Collection and then filter appropriately.

$products = Mage::getModel('catalog/category')->load($category_id)
 ->getProductCollection()
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('status', 1)
 ->addAttributeToFilter('visibility', 4)
 ->addAttributeToFilter('special_price', array('neq' => ""))
 ->setOrder('price', 'ASC')
 ;