top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to get product collection of a category in Magento?

+3 votes
618 views
How to get product collection of a category in Magento?
posted Apr 22, 2015 by Rahul Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

You can use magento object to filter.

$categoryId = 123; // a category id that you can get from admin
$category = Mage::getModel('catalog/category')->load($categoryId);

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category)
    ->load();

print_r($products);
answer Apr 25, 2015 by Vrije Mani Upadhyay
0 votes

My category id is

<?php $catid=10 ;?>
I got all product by writing the below code
<?php
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //My cat id is 10
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
}?>

Now you have all the product ids in $prdIds variable. Just click here to get all details of the product from a particular product id.You can get individual product id by the following loop.

<?php
foreach($prdIds as $_prdIds){
$product_id = $_prdIds;
$obj = Mage::getModel(‘catalog/product’);
$_product = $obj->load($product_id); // Enter your Product Id in $product_id
// get Product’s name
echo $_product->getName();
//get product’s short description
echo $_product->getShortDescription();
//get Product’s Long Description
echo $_product->getDescription();
//get Product’s Regular Price
echo $_product->getPrice();
//get Product’s Special price
echo $_product->getSpecialPrice();
//get Product’s Url
echo $_product->getProductUrl();
//get Product’s image Url
echo $_product->getImageUrl();
}
?>
answer Aug 31, 2016 by Magento_ocodewire
...