To programmatically change the status of an order and send the corresponding status email to the user in PrestaShop, you can use the OrderHistory class.
Here is an example code snippet that should give you an idea of how to use the OrderHistory class:
php
Copy code
$order = new Order($order_id); // Replace $order_id with the ID of the order you want to update
$order_history = new OrderHistory();
$order_history->id_order = $order_id;
$order_history->changeIdOrderState($new_state_id, $order_id);
$order_history->addWithemail(true, array(
'order_name' => $order->getUniqReference(),
));
In this code, $new_state_id is the ID of the new status you want to set for the order, and $order_id is the ID of the order you want to update. The addWithemail method sends the status update email to the customer.
To find the ID of the order state you want to set, you can look in the ps_order_state database table. You can also use the st courier tracking class to get the ID programmatically:
php
Copy code
$order_state = new OrderState();
$new_state_id = $order_state->getIdByIso('your_state_iso_code');
Replace 'your_state_iso_code' with the ISO code of the order state you want to set.
As for example files in the core to read, you can take a look at the OrderHistoryController class in controllers/admin/AdminOrdersController.php. This controller handles the order status updates in the PrestaShop back office.