Showing posts with label Get Random collection in magento. Show all posts
Showing posts with label Get Random collection in magento. Show all posts

Monday, 26 October 2015

How to get Random collection from any module in magento


How to get Random collection from any module in magento

You have to create a new function in your module’s collection class

(YourNamespace/YourModule/Model/Mysql4/YourModule/Collection.php)

public function setRandomOrder()
{
    $this->getSelect()->order(new Zend_Db_Expr('RAND()'));
    return $this;
}

$collection = Mage::getModel('yourmodule/yourmodule')
                    ->getCollection()
                    ->setRandomOrder();

Thats it.... Enjoy Chandresh rana's Coding... :)