Avenir | Drupal Development | Joomla Development | Magento Development | OsCommerce Development

Monday 25 April 2011

Add sorting to the collections of records in Custom Magento

File Path

/var/www/html/app/design/frontend/base/default/template/yourfoldername/XXX.PHTML

Add the following code in above mentioned file
$collection = Mage::getModel('avenirgallery/avenirgallery')->getCollection()->addAttributeToSort('avenirgallery_id','desc');

Add the Following function into /var/www/html/app/code/local/Avenir/Avenirgallery/Model/Mysql4/Avenirgallery/Collection.php

public function addAttributeToSort($attribute, $dir='asc') {
$this->getSelect()->order("{$attribute} {$dir}");
return $this;
}

By Radha,
Avenir Team

Tuesday 5 April 2011