Magento – Fetch All The Products Under A Certain Category

If you want to fetch all the products under a certain category in Magento, use the below code –

$catObj = Mage::getModel('catalog/category')->load($catId);
$prodObj = $catObj->getProductCollection()->getData();

Here $catId is the id of the category whose product you want to fetch. And $prodObj will return the array of products, each of whose values will be an array like –

Array(
[entity_id] => 1
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => product-a
[has_options] => 0
[required_options] => 0
[created_at] => 2011-01-12 19:01:24
[updated_at] => 2011-01-12 19:01:24
[cat_index_position] => 1
)

Leave a comment

Your email address will not be published. Required fields are marked *