magento product from category id

magento product from category id – How to get all products from a particular category id in magento

how to get magento product from category :: In this post we will show you how to get magento product from category id. we will give you code for get all products of a particular category id.

Hear we get products id data from category id. following code will 1st get all product id and after it we will get data of products. in this code you need to pass your

// run as .php file or external php file
// Mage file include  
// include_once "app/Mage.php";  
// Controller file include 
// include_once "downloader/Maged/Controller.php"; 

// pass your category id 
$your_cat_id = 17;

// get category for magento products
$getcategory = new Mage_Catalog_Model_Category();
$getcategory->load($your_cat_id);

// get category detail for magento product from category
$prodCollection = $getcategory->getProductCollection();
if ($getcategory->getIsActive()) 
{
	foreach ($prodCollection as $product) 
	{
		// get product ids
		$allProductIds[] = $product->getId();
	}
	$count_product = count($allProductIds);
	if($count_product > 0)
	{
		// get product object
		$catalogObj = Mage::getModel('catalog/product');
		foreach ($allProductIds as $productIds)
		{
			// get product data from product id 
			$_product = $catalogObj->load($productIds);
			// print Name 
			echo $_product->getName()."<br>";
			// print Product Url 
			echo $_product->getProductUrl()."<br>";
			// print Image Url
			echo $_product->getImageUrl()."<br>";
			echo "<br><br>";
		}		
	}
	else
	{
		echo "<p class='note-msg'>There are no products matching the selection.</p>";
	}
	
}
else
{
	echo "<p class='note-msg'>There are no products matching the selection.</p>";
}

Leave a Comment

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

3  +  3  =  

We accept paid advance and paid guest Posting on our Site : Contact US