search
top

Product Collection in Magento

Hello All,

I am writing here the script to get product collection of the store.


<?php



	$collection = Mage::getResourceModel('catalog/product_collection');  		   

	$collection->addAttributeToFilter('status',1); //only enabled product

	$collection->addAttributeToFilter('visibility',array("neq"=>1)); //except not visible individually

	$collection->addAttributeToSelect(array('name','url','small_image')); //add product attribute to be fetched

        //$collection->getSelect()->order('rand()');	 //uncomment to get products in random order   

        $collection->addStoreFilter();            

        if(!empty($collection))

        { 

     	    foreach ($collection as $_product): 

			echo $_product->getName();	//get product name			

	    endforeach;

        }else 

        {

    	     echo 'No products exists';

        }       

        

?>	

Hope this is helpful

Leave a Reply

top