PHP – Get Order Status Name by State Code in Magento 1.9

magento-1.9order-stateorder-statussales-order

I am working on an extension and i need an info how to get the status name by state code, is it possible ?

enter image description here

The picture is from the Admin's panel Order Statuses page.

How i can get the status name by state code, is it possible ?

Best Answer

No, because it is a 1:n association, there are multiple statuses per state.

You can, however, get a list of all statuses that are assigned to a state $stateCode, and their names, with:

$statuses = Mage::getResourceModel('sales/order_status_collection')
    ->addStateFilter($stateCode)
    ->toOptionHash();

$statuses then contains an array in the form $statusCode => $statusName

Update:

According to your comments, you will need this:

$status = Mage::getModel('sales/order_status')->loadDefaultByState($stateCode);
echo $status->getStoreLabel();

(outputs the name of the default status for state with code $stateCode)

Related Topic