0

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?

1
  • MmynameStackflow, if my answer helped you in any way, please feel free to set as correct :) Feb 11, 2018 at 11:24

3 Answers 3

3

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

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)
0

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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