Reputation: 41
I'am developing module, which after „Payment Accepted“ state executs it's own process and if everything ok - changes order state to Shipped. For that I'am using hookActionOrderStatusUpdate:
public function hookActionOrderStatusUpdate($params)
{
if($params['newOrderStatus']->id == 2)
{
if(!$this->doSomething())
return false;
}
return /*function for changing order's state*/;
}
But problem is, that new order status changes before „Payment Accepted“. Example:
Does anyone know how to reslove that problem? P. S. tried hookActionOrderStatusPostUpdate. PS 1.6.0.9
Upvotes: 4
Views: 5319
Reputation: 517
You just can't change the order status into the actionOrderStatusUpdate
hook.
This problem happen because the hook is executed way before the OrderHistory
is actually registered into the database due to only one thing:
The function where the hook is executed does not save the OrderHistory
into the database which is processed by the ->add
or ->addWithemail
methods -- executed manually from external script.
Eg this five lines in the PaymentModule
class :
$new_history = new OrderHistory();
$new_history->id_order = (int) $order->id;
// This line exec the Hook
$new_history->changeIdOrderState((int) $id_order_state, $order, true);
// This line save the OrderState into the database
$new_history->addWithemail(true, $extra_vars);
A workaround to this issue would be to use actionOrderHistoryAddAfter
or actionObjectOrderHistoryAddAfter
instead.
This was undocumented before I made a PR to the docs and caused many trouble and misundertanding around this hook.
Upvotes: 1
Reputation: 49
I had similar problem and I used combination of hookActionOrderStatusUpdate
and hookActionOrderHistoryAddAfter
.
Reason for that is that hookActionOrderHistoryAddAfter
really can add another status after "paid" status. And hookActionOrderStatusUpdate
adds its before "shipped", but hookActionOrderHistoryAddAfter
does not know about status which going to be set.
So it does looks like this:
class MikolaHooks extends Module
{
public $newOrderStatusId = NULL;
public function hookActionOrderStatusUpdate($params) {
$this->newOrderStatusId = $params['newOrderStatus']->id;
}
public function hookActionOrderHistoryAddAfter($params) ....
Upvotes: 2
Reputation: 872
Please try displayOrderConfirmation and displayPaymentReturn hooks. These hooks receives an order detail in params variable after making payment.
Upvotes: 1