Reputation: 11
I have a problem with custom module to prestashop 1.7.6. I try to change order status - it works fine but sometimes it dosn't trigger hookActionOrderStatusPostUpdate
This is my loop to change order state.
foreach ($ordersIds as $orderId) {
$order = new Order($orderId);
if($order->current_state != $newStatusId) {
$history = new OrderHistory();
$history->id_order = (int)$order->id;
$history->changeIdOrderState($newStatusId, $order);
$history->addWithemail(true);
$history->save();
}
}
Sometimes there is a problem that order status is changed properly, but hookActionOrderStatusPostUpdate was not triggered.
Upvotes: 1
Views: 74
Reputation: 1479
I think you're using the wrong hook.
The actionOrderStatusPostUpdate
hook is triggered before new OrderStatus()
is saved to the database. You should use the actionOrderHistoryAddAfter
hook instead.
More details on the hooks are available on the Prestashop developer documentation: https://devdocs.prestashop-project.org/1.7/modules/concepts/hooks/list-of-hooks/
Upvotes: 1