Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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)

share|improve this answer
    
But what if there is only one status by the state code ? –  The Lex Nov 30 at 20:54
    
Then my code results in an array with one element and you can use that element. –  fschmengler Nov 30 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. –  fschmengler Nov 30 at 20:56
    
When i do that i got result giving only Array and no name.. –  The Lex Nov 30 at 20:56
    
You cannot echo an array. PHP basics... –  fschmengler Nov 30 at 20:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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