Skip to main content

restore canceled order in Magento2

Imagine that some of your team cancel an order in Magento by mistake, What is the solution?
By the below code you can restore the cancelation, hope it will help you

 

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

$order->setState("processing")
    ->setStatus("processing")
    ->save();

$orderItems = $order->getAllItems();
foreach ($orderItems as $item) {
    $item->setData("qty_canceled",0)->save();
}