I want to sort the customer attribute address after sort_order
. For some reason by default it doesn't work so I started to digging into the core. This function :
protected function _getFormAttributeCollection()
{
return parent::_getFormAttributeCollection()
->addFieldToFilter('attribute_code', array('neq' => 'created_at'));
}
from Mage_Customer_Model_Form
is responsible . If I add here this code ->setOrder('sort_order', 'ASC');
to my collection its working fine. Due to the fact that you don't touch the core, I want to fix this from an observer.
I used this event: core_block_abstract_to_html_before
and this is my function from my observer:
$grid = $observer->getBlock();
if ($grid instanceof Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element) {
$collection = $observer->getEvent()->getCollection();
$collection = $collection->getSelect()->order('sort_order', 'ASC');
// $collection->setOrder('sort_order', 'ASC');
$observer->getEvent()->setCollection($collection);
}
The fact is that $collection is always null. I don't know why ? Can someone give me an idea how to fix this ?
Thank you