2
$orderId = $orderId;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
$order->setState(\Magento\Sales\Model\Order::STATE_NEW, true);
$order->setStatus("awaiting_stock");
$order->setUpdate_at(date('2017-03-20 10:14:23', time() - 60*60*24));
$order->addStatusToHistory($order->getStatus(), 'Awaiting Stock');
$order->save();
1

For me

Its not good to use the object manager. Instead you can use the Magento\Sales\Model\OrderRepository to load the order You can use the get($entityId) method . And then you can try $order->addCommentToStatusHistory($comment, $status = false, $isVisibleOnFront = false); $order->save() .

Note addStatusToHistory addStatusHistoryComment are deprecated

Hope this will help

Raviraj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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