3

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 ?

7

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)

  • But what if there is only one status by the state code ? – Venelin Vasilev Nov 30 '14 at 20:54
  • Then my code results in an array with one element and you can use that element. – Fabian Schmengler Nov 30 '14 at 20:54
  • But I would prefer this: Mage::getModel('sales/order_state')->loadDefaultByState($staeCode) - will return the default status. If there is only one status, it will return this as well. If there are more, it will not give you the first it finds but the default status. – Fabian Schmengler Nov 30 '14 at 20:56
  • When i do that i got result giving only Array and no name.. – Venelin Vasilev Nov 30 '14 at 20:56
  • 1
    You cannot echo an array. PHP basics... – Fabian Schmengler Nov 30 '14 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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