Changing magento order status and button action on admin

Changing magento order status and button action on admin

October 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Changing magento order status and button action on admin

Changing Magento Order Status Automatically on Admin Actions

As an experienced e-commerce developer working for Laravel Company, I frequently encounter requests to automate order status changes in the Magento admin interface. In this post, we’ll explore how to achieve the desired functionality you described.

Understanding the Current Flow

In a default Magento installation, when an administrator prints an invoice or ships an order, they manually change the status using the dropdown menu provided. This two-step process can lead to errors and inefficiencies if not followed correctly.

The app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php file you mentioned is part of the core Magento codebase responsible for rendering the order view in the admin panel. However, modifying core files directly is generally discouraged due to upgrade compatibility issues.

Automating Status Changes on Button Click

To automate status changes upon button click, we’ll need to override the app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php file and modify its behavior using an observer and a model. Here’s a step-by-step guide:

Step 1: Create a custom module

Create a new module in your local Magento installation under app/code/local/Local/Namespace. This will house all the necessary files for our custom functionality.

Step 2: Override the order view block

In your new module, create the following file structure:

/app/code/local/Local/Namespace/etc/config.xml

Add the following XML configuration to override the core sales_order_view block:

<config>
    <global>
        <blocks>
            <local_namespace>
                <class>Local_Namespace_Block</class>
            </local_namespace>
        </blocks>
    </global>
  <frontend>
      <layout>
          <updates>
              <sales_order_view>
                  <file>local_namespace.xml</file>
              </sales_order_view>
          </updates>
      </layout>
  </frontend>
</config>

This configuration tells Magento to use our custom block Local_Namespace_Block_Sales_Order_View instead of the core one.

Step 3: Create the observer

Create a new observer file in your module:

/app/code/local/Local/Namespace/etc/config.xml

Add the following XML configuration for the observer:

<config>
    <global>
        <events>
            <sales_order_view_button_print_invoice>
                <observers>
                    <local_namespace_observer>
                        <type>singleton</type>
                        <class>Local_Namespace_Model_Observer</class>
                        <method>printInvoiceAction</method>
                    </local_namespace_observer>
                </observers>
            </sales_order_view_button_print_invoice>
        </events>
    </global>
</config>

This observer will trigger when the print invoice button is clicked.

Step 4: Create the observer method

Create a new file Observer.php in your module:

/app/code/local/Local/Namespace/Model/Observer.php

Add the following code for the printInvoiceAction method:

class Local_Namespace_Model_Observer
{
    public function printInvoiceAction($observer)
    {
        $orderId = $observer->getOrder()->getId();
        $order = Mage::getModel('sales/order')->load($orderId);

        // Set the order status to 'shipped'
        $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
        $order->save();

        return $this;
    }
}

This method retrieves the order ID from the observer event and loads the corresponding order object. It then sets the order state to ‘complete’ (which corresponds to ‘shipped’) and saves it.

Conclusion

By following this approach, you can automate the status change process in your Magento admin panel without directly modifying core files. This ensures better upgrade compatibility and easier maintenance of your custom functionality.

Remember that working with observers and block overrides requires a solid understanding of Magento’s event-driven architecture. Be sure to thoroughly test your changes before deploying them to a production environment.

For more advanced customizations and extensions, consider reaching out to the expert team at Laravel Company for professional assistance in enhancing your e-commerce platform.

Extensions Admin Deployment Orders

Our network