/*
We have to flush the status changes directly, because the "createStatusMail" function in the
sOrder.php core class, use the order data from the database. So we have to save the new status before we
create the status mail
*/
$statusBefore =
$order->
getOrderStatus();
$clearedBefore =
$order->
getPaymentStatus();
// Refresh the status models to return the new status data which will be displayed in the batch list
if (!
empty($data['status'
]) ||
$data['status'
] === 0
) { $order->
setOrderStatus($modelManager->
find(Status::
class,
$data['status'
]));
} if (!
empty($data['cleared'
])) { $order->
setPaymentStatus($modelManager->
find(Status::
class,
$data['cleared'
]));
} try { $modelManager->
flush($order);
} catch (Exception
$e) { $data['success'
] = false;
$data['errorMessage'
] =
sprintf( $namespace->
get('save_order_failed', 'Error when saving the order. Error: %s'
),