Sunday, July 15, 2012

Magento: List out the products from Category ID

Here we have to display all the products from single category using category ID. If we know category ID, We display all the product lists. Category ID is 6. We need to display all the products under 6th category, Use the following code to display all the products,

<?php
$catid = 6;
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //My category id is 6
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$prdIds[] = $product->getId(); //Array to store all the product ids
}
?>


In the above code to get all the products ID from category 6. Then we  need to Use following code to get Product information from the $prdIds[] Array.

<?php foreach($prdIds as $product_id); {
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($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();
}?>


Please update your comments to improve Next level in Magento Product Display. Thank you.

By PHP with 2 comments

2 comments:

Post a Comment

    • Popular
    • Categories
    • Archives