Social Icons

twitterfacebookgoogle pluslinkedinemail

Wednesday 10 April 2013

Get Only Column , First item , Last item , or convert to xml from Collection

if you want to get only one column from product collection. you can write look like.

$product_collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');




var_dump($product_collection->getColumnValues('name'));


get product with name anant

var_dump($product_collection->getItemsByColumnValue('name','anant'));





get first or last item/row from the collection



var_dump($product_collection->getFirstItem()->getData());
echo $product_collection->getFirstItem()->getName();

echo $product_collection->getLastItem()->getName();
var_dump($product_collection->getLastItem()->getData());  

get Collection data as XML or convert collection in xml

var_dump($product_collection->getFirstItem()->toXml() );





No comments :

Post a Comment

 

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement