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.');

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?

1 Answer 1


First off, postdispatch event observer will not work because the blocks and layouts have already loaded, which means the messages block has already been initialised and set to display already loaded session storage messages.

There may be away to inject it but it just gets too complicated from there.

A better solution is to use the following dispatched event: controller_action_predispatch_adminhtml_sales_order_grid

 * Check order id
 * @param Varien_Event_Observer $observer
public function checkOrderId(Varien_Event_Observer $observer)
    $action = $observer->getControllerAction();
    $filter = $action->getRequest()->getParam('filter');
    $requestData = Mage::helper('adminhtml')->prepareFilterString($filter);

    if (!empty($requestData['real_order_id'])) {
        $orderId = $requestData['real_order_id'];

        // Example order id check below
        if ($orderId == '100000033') {
            Mage::getSingleton('core/session')->addNotice($orderId . ' is from the old system.');

Basically we fetch the filter value once it hits the router, and the rest is all self explanatory.

The layout is then loaded and rendered within the controller itself which will then populate the message.

  • Yes, the solution I landed on was getting the filters from the $_GET parameter instead of the block's column. Apr 16, 2015 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.