I am using sales_order_save_after event to change order status. It's working fine for all order status except STATE_COMPLETE. when i set the order status STATE_COMPLETE to make order Complete but it changed to Closed instead of being Complete. Other order States is working fine. The issue only happening when i try to use STATE_COMPLETE.
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
if($order->getState() != 'complete') {
$order->setState(\Magento\Sales\Model\Order::STATE_COMPLETE)->setStatus(\Magento\Sales\Model\Order::STATE_COMPLETE);
$order->save();
}
}
This is what i'm doing
Can anyone help me out to make order status to "Complete" via observer ?