0

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

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Ederico Rocha
  • 250
  • 4
  • 10

1 Answers1

2

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.

Domen Vrankar
  • 1,743
  • 15
  • 19
  • I tried this and `exception 'Exception' with message 'Warning: include(Mage/Sales/Model/Order/Status/State.php) [function.include]: failed to open stream: No such file or directory in /home/hdmpt/public_html/gtdev/fresh/lib/Varien/Autoload.php on line 93' in /home/hdmpt/public_html/gtdev/fresh/app/code/core/Mage/Core/functions.php:245` – Ederico Rocha Jan 25 '13 at 16:04
  • You are correct. I have modyfied the answer accordingly – Domen Vrankar Jan 25 '13 at 16:13