Search code examples
magentostatestatusecommerce-sales

Magento 1.7.0.2 collect and extract order status state


I've searched everywhere for this and can't find an answer that works.

How do I get a collection of all the sales/order_status_state. One uses a ResourceModel or a simple Model ?

Thank you


Solution

  • You could use

    $collection = Mage::getResourceModel( 'sales/order_status_collection' )->joinStates();
    

    or

    $collection = Mage::getSingleton( 'sales/order_status' )->getCollection()->joinStates();
    $collection = Mage::getModel( 'sales/order_status' )->getCollection()->joinStates();
    

    They all return a collection but the first one returns collection directly, the singleton version uses a singleton so calling getSingleton for the same model twice creates only one class instance and then creates a new collection and getModel version would for two calls create two different models and then create collections the same way as getSingelton version.

    So the difference is only in overhead in how many classes it creates before returning a collection.

    You weren't able to use 'sales/order_status_state' directly because model, resource model and collection for it don't exist - state is joined to status collection with joinStates() function.