I'm using observer method sales_order_save_before
to do some operations based on order state
$order = $observer->getEvent()->getOrder();
$initialState = $order->getOrigData('state');
$newState = $order->getData('state');
if($initialState != $newState && $newState == 'processing'){
// Do some operation
}
if($initialState != $newState && $newState == 'complete'){
// Do some operation
}
First validation is working fine whereas in second if loop both the conditions are not being true at the same time.
I did some modifications in order and digged dipper into its status. What I see is when first time order is placed it's status and state is processing . When order is shipped and invoiced in admin it's status becomes complete but state still remains processing. When the status is complete and I write a comment on this order then it's state becomes complete due to which second if loop is not working.
How I can validate the loop when the order state becomes complete ? (initialState should be different than newState).