Magento 2 – List of Order States and Statuses

magento2order-stateorder-status

I looked for a way to create an option list of order states and statuses but couldn't find a way. I did found something about a statusfactory but couldn't find a way to get a list out of it and especially of the states.

I need a list of available states and a list of available statuses. Can someone help me or point me in the right direction?

Best Answer

Use Magento\Sales\Model\ResourceModel\Order\Status\Collection class to get status collection

protected $statusCollection;

public function __construct(
    ...
    \Magento\Sales\Model\ResourceModel\Order\Status\Collection $statusCollection,
    ...
) {
    ...
    $this->statusCollection = $statusCollection;
    ...
}

public function getStatusCollection()
{

    $collection = $this->statusCollection->toOptionArray();

    echo "<pre>";
    print_r($collection);
}
Related Topic