Magento 2.3 Change Order Status Programmatically

by Shimon   Last Updated February 11, 2019 09:09 AM

How to Order status change Processing to complete in magento 2.3



Answers 2


You can get programmatically this way..

    $orderId = 1; // here order id

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $order = $objectManager->create('\Magento\Sales\Model\Order')
                               ->load($orderId); 

    $order->setState("complete")->setStatus("complete");

    $order->save();
Rakesh Donga
Rakesh Donga
February 11, 2019 08:34 AM

You can Change the order status to complete using repository Class of order entity \Magento\Sales\Api\OrderRepositoryInterface

    $order = $this->orderRepository->get($orderiId);
    $order->setStatus($completeStatus)->setState($completeStatus);
    $this->orderRepository->save($order); 

Code Looks Like:

<?php
namespace {ClassNameSpace};

use Magento\Framework\Exception\NoSuchEntityException;

class Test {

    /**
     * @var \Magento\Sales\Api\OrderRepositoryInterface
     */
    private $orderRepository;

    public function __construct(
    \Magento\Sales\Api\OrderRepositoryInterface $orderRepository      
    ) {

        $this->orderRepository = $orderRepository;
    }
    public function ChangeOrderStatusToComplete()
    {
        $completeStatus = Magento\Sales\Model\Order::STATE_COMPLETE;
        $id = 2;
        try{
            $order = $this->orderRepository->get($id);
            $order->setStatus($completeStatus)->setState($completeStatus);
            $this->orderRepository->save($order);           
        } catch (NoSuchEntityException $ex) {
            // error Happen
        }


    }
}
Amit Bera
Amit Bera
February 11, 2019 09:03 AM

Related Questions


Updated May 14, 2015 22:04 PM

Updated February 22, 2017 16:09 PM

Updated March 29, 2017 13:09 PM

Updated August 15, 2018 11:09 AM

Updated March 01, 2017 21:09 PM