Background
I am migrating a site to the Magento platform. I have a requirement to notify the admin if they're searching for an order that comes from the old platform. I have table of old orders. I'm trying to use an observer, so that when the admin tries to filter by Order Number, I can see if that number matches an order from the old system. If it does, I want to display a notice telling the admin that they can find details on this order by logging into the old system.
What I've tried
In my observer I have
$block = Mage::app()->getLayout()->getBlock('sales_order.grid');
foreach ($block->getColumns() as $column) {
if ($column->getIndex() == 'increment_id' && $column->getFilter()->getValue()) {
$value = $column->getFilter()->getValue();
if ($this->orderExistsInOld($value)) {
Mage::getSingleton('core/session')->addNotice($value . ' is from the old system.');
break;
}
}
}
Here I am detecting if the admin has entered a filter value for increment_id
. If it does, I check the old system with orderExistsInOld
. If a match is found I display a notice.
The problem
I can't seem to find the event I should be using my observer on.
controller_action_predispatch_adminhtml_sales_order_grid
is too early. The block hasn't been rendered and the filters aren't set.controller_action_postdispatch_adminhtml_sales_order_grid
is late enough that filters are set and my conditions work. However, it's so late that the session notice isn't being shown. You can only see it after a refresh.
I've also tried various abstract block render events I checked for the order grid but I can't seem to get it work.
How can I show a notice in the admin grid based on the current filters?