Get product info in Magento

Here is a code snippet to get all products to an array and print the names out.

$products_collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');
foreach($products_collection as $product)
{
    echo $product->getName()."<br/>";
}

Here is a code snippet to get all products from a root category to an array, and print the name, price, image url and product url for each product.

<?php
$_rootcatID = Mage::app()->getStore()->getRootCategoryId();

$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => $_rootcatID))
->addAttributeToSelect('*');
$_testproductCollection->load();


foreach($_testproductCollection as $_testproduct){ 
    echo $_testproduct->getName()."***";
	echo $_testproduct->getFormatedPrice()."***";
	echo $this->helper('catalog/image')->init($_testproduct, 'image')."***";
	echo $_testproduct->getProductUrl();
	echo "</br>";

};
echo get_class($_testproductCollection);
echo get_class($this);

?>

Search within Codexpedia

Custom Search

Search the entire web

Custom Search