Get product info in Magento
Here is a code snippet to get all products to an array and print the names out.
[code language=”php”]
$products_collection = Mage::getModel(‘catalog/product’)
->getCollection()
->addAttributeToSelect(‘*’);
foreach($products_collection as $product)
{
echo $product->getName().”
“;
}
[/code]
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.
[code language=”php”]
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 ““;
};
echo get_class($_testproductCollection);
echo get_class($this);
?>
[/code]
Search within Codexpedia
Search the entire web