Get Magento defined values for model "sales/order" status

Get Magento defined values for model "sales/order" status

October 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get Magento defined values for model "sales/order" status

Retrieving Magento Defined Status for Sales/Orders

As an experienced developer, I understand your need to compare order status against Magento-defined values instead of hardcoded strings. This practice enhances the maintainability of your code and ensures consistency with the platform’s core functionality.

Understanding Magento Order Statuses

In Magento, each sales/order model can have a status that represents its current state in the order management lifecycle. These statuses are defined as constants within the Mage_Sales_Model_Order class. They include states like “pending”, “processing”, “complete”, and others.

Getting Magento Defined Order Status

To retrieve these defined values, you need to access the constants directly from the model class using Reflection API or by following the object-oriented approach with protected properties in the model.

Using Reflection API:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
$statusConstant = new ReflectionClass('Mage_Sales_Model_Order');
$processingStatusValue = $statusConstant->getConstants()['STATUS_PROCESSING'];

In this example, the ReflectionClass helps you access the constants defined in the Mage_Sales_Model_Order class. The getConstants() method returns an associative array containing all the constants.

Using Protected Properties:

You can also directly access these values as protected properties within the model:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
if ($order->getStatus() === $order->STATUS_PROCESSING) {
    // Do stuff with the order
}

This approach is more object-oriented and easier to read, as it directly references the property from the model instance.

Comparing Order Status

Now that you have access to the Magento-defined status values, you can replace your string comparisons:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
if ($order->getStatus() === $order->STATUS_PROCESSING) {
    // Do stuff with the order
}

Or using Reflection API:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
$statusConstant = new ReflectionClass('Mage_Sales_Model_Order');
if ($order->getStatus() === $statusConstant->getConstants()['STATUS_PROCESSING']) {
    // Do stuff with the order
}

In both cases, you’re comparing the order status directly to the defined constant values, ensuring your code remains consistent and easy to maintain.

Conclusion

Retrieving Magento-defined values for order statuses is crucial for writing robust and maintainable extensions. By using either Reflection API or accessing protected properties in the model class, you can achieve this elegantly while keeping your code tightly coupled with Magento’s core functionality.

Remember that understanding how the platform works internally helps you create more stable and efficient extensions. For a deeper dive into Magento core concepts, consider checking out our Magento Developer Guide for in-depth tutorials and best practices.

Happy coding!

API Orders

Our network