cancel
Showing results for 
Search instead for 
Did you mean: 

Re-stocks product after the order is canceled

Re-stocks product after the order is canceled

Cheers!

 

I have this piece of code in a cron that goes through all orders returned from a query and cancel them. How can I re-stock the items belonging to the canceled order ? 

 

$ordernumber = intval($order['increment_id']);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($ordernumber);

$order->setState('canceled')->setStatus('canceled');
$order->save();

 Thanks