- Posts: 11
- Thank you received: 0
Quick onAfterOrderConfirm question
6 years 4 months ago #319606
by nozaro33
Quick onAfterOrderConfirm question was created by nozaro33
I want to run code that after order confirm sends SMS, I can directly use this trigger without caring what payment gateway it is correct?
function onAfterOrderConfirm(&$order){
//Run my SMS code here
}
Thanks so much
function onAfterOrderConfirm(&$order){
//Run my SMS code here
}
Thanks so much
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319608
by nicolas
Replied by nicolas on topic Quick onAfterOrderConfirm question
Hi,
No that trigger is called after the checkout for the payment method selected so that it can redirect to the payment gateway.
What you want to do is to implement instead the "onAfterOrderUpdate" trigger and check the $order->order_status and the $order->old->order_status so that you can see the order is going from "created" to "confirmed" and then run your code.
Doing it like this will indeed work regardless of the payment method being used (unless the payment plugin directly creates the order as confirmed, in that case, you'll want to also implement the onAfterOrderCreate trigger and check the order status in $order->order_status).
When we develop such plugin to act upon an order being paid, we usually implement both the onAfterOrderUpdate and onAfterOrderCreate so that we can take into account all the ways different payment plugins can work.
No that trigger is called after the checkout for the payment method selected so that it can redirect to the payment gateway.
What you want to do is to implement instead the "onAfterOrderUpdate" trigger and check the $order->order_status and the $order->old->order_status so that you can see the order is going from "created" to "confirmed" and then run your code.
Doing it like this will indeed work regardless of the payment method being used (unless the payment plugin directly creates the order as confirmed, in that case, you'll want to also implement the onAfterOrderCreate trigger and check the order status in $order->order_status).
When we develop such plugin to act upon an order being paid, we usually implement both the onAfterOrderUpdate and onAfterOrderCreate so that we can take into account all the ways different payment plugins can work.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319619
by nozaro33
Replied by nozaro33 on topic Quick onAfterOrderConfirm question
Got it, thanks so much!
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319755
by nozaro33
Replied by nozaro33 on topic Quick onAfterOrderConfirm question
so if payment plugin sends back payment confirmation change order to confim, onAfterOrderUpdate the trigger should be
if( $order->old->order_status =='created' && $order->order_status == 'confirmed') correct?
But if I have a trigger that is order_status == confirm (and ignore the ->old->order_status, then the function would be sent twice if an admin changed the order created -> to confirmed manually from back end. I hope I'm making sense...
Thanks!
if( $order->old->order_status =='created' && $order->order_status == 'confirmed') correct?
But if I have a trigger that is order_status == confirm (and ignore the ->old->order_status, then the function would be sent twice if an admin changed the order created -> to confirmed manually from back end. I hope I'm making sense...
Thanks!
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319756
by nozaro33
Replied by nozaro33 on topic Quick onAfterOrderConfirm question
also, it works for manual backend set to confirm, but if payment gateway sends back confirmation after paid and order status is changed to confirm, the plugin doesn't work
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319776
by nicolas
Replied by nicolas on topic Quick onAfterOrderConfirm question
Hi,
The plugin will also be triggered for the onAfterOrderUpdate when the payment plugin changes the status of the order to confirmed after the payment. That is unless the payment plugin isn't coded properly.
Note however that in such case, the order confirmation usually happens with a direct request from the payment gateway server to your server. So as a customer you don't see anything on the interface.
If you want to check that the trigger is called in such case, you need to write text in a file and then check that file content.
The plugin will also be triggered for the onAfterOrderUpdate when the payment plugin changes the status of the order to confirmed after the payment. That is unless the payment plugin isn't coded properly.
Note however that in such case, the order confirmation usually happens with a direct request from the payment gateway server to your server. So as a customer you don't see anything on the interface.
If you want to check that the trigger is called in such case, you need to write text in a file and then check that file content.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319804
by nozaro33
Replied by nozaro33 on topic Quick onAfterOrderConfirm question
Thank you, I found out the problem is payment notification can't run " $orderInDb = $orderClass->loadFullOrder($order->order_id); "
that's correct right?
that's correct right?
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319809
by nicolas
Replied by nicolas on topic Quick onAfterOrderConfirm question
Hi,
Well, yes and no.
If you call it like that, it will only work if the current user session is the owner of the order.
Otherwise, if you want to load the data regardless, you want to do like that :
$orderInDb = $orderClass->loadFullOrder($order->order_id, false, false);
That will deactivate the check of the user.
Well, yes and no.
If you call it like that, it will only work if the current user session is the owner of the order.
Otherwise, if you want to load the data regardless, you want to do like that :
$orderInDb = $orderClass->loadFullOrder($order->order_id, false, false);
That will deactivate the check of the user.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319829
by nozaro33
Replied by nozaro33 on topic Quick onAfterOrderConfirm question
I get it now, thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.177 seconds