Wednesday 23 April 2014

Useful Collection Functions of Magento


Useful Collection Functions of Magento

$collection->getSelect();

To get select string of sql object

$collection->getSelect()->getSelectSql();

To get the size of collection

$collection->getSelect()->getSize();

To get distinct selection

$collection->getSelect()->distinct($flag);

To get all data array for collection

$collection->getSelect()->getData();

To set an order to the collection

$collection->getSelect()->setOrder($field, $direction);

To print the query or log the query

$collection->getSelect()->printLogQuery(true, true);

To get collection items

$collection->getSelect()->getItems();

To get first item of the collection


$collection->getSelect()->getFirstItem();

To get last item of the collection

$collection->getSelect()->getLastItem();

To get current collection page number

$collection->getSelect()->getCurPage();

To get total collection pages

$collection->getSelect()->getPageSize();

To clear the collection

$collection->getSelect()->clear();

No comments: