Question

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?

Was it helpful?

Solution

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);
}

OTHER TIPS

You can get the list using the class

Magento\Sales\Model\ResourceModel\Order\Status\Collection

There you will see also

/**
 * Join order states table
 *
 * @return $this
 */
public function joinStates()

and

/**
 * Add state code filter to collection
 *
 * @param string $state
 * @return $this
 */
public function addStateFilter($state)

Try this class which gives you list of all order status and state Magento\Sales\Model\Config\Source\Order\Status in this class there is a method toOptionArray()

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top