Magento 2 platform is capable of hosting a modern E-commerce store with out of the box functionalities and powerful features.
However, the businesses are also innovating and the customers’ expectations are rising each day. To match these expectations and stand apart from the competitors, the store owners demand powerful features and facilities in the store from the Magento 2 developer.
One such similar scenario was when I had to get the collection of order statuses in Magento 2.
I required the order status collection in order to implement an action on the basis of the order status for which I used the below code. Likewise you can also change order status programmatically in Magento 2.
You can also use this solution when you want to perform an action on the condition of the order status. For example, call an API or generate an invoice for the orders with specific order status only.
Method to get the collection of order status in Magento 2:
use Magento\Sales\Model\ResourceModel\Order\Status\Collection as OrderStatusCollection; private $orderStatusCollection; public function __construct(OrderStatusCollection $orderStatusCollection) { $this->orderStatusCollection=$orderStatusCollection; } public function getAllOrderStatus(){ return $this->orderStatusCollection->toOptionArray(); }
That’s it.
Also, feel free to share the solution with fellow Magento 2 developers via social media working to meet the customers’ expectation
Thank you.