There is a payment plugin which has a plgVmOnUpdateOrderPayment method. When the order status is changed to a specified status (e.g. 'S') I want to change the comments message which is stored in #__virtuemart_order_histories and VM sends it in the mail. How should I do that?
which payment plugin?
It depends on why you want to do this.
Were you aware that the latest version of VM allows you to specify an email override for a status.
Which means you can make your own email and have that sent when the relevant status(s) is/are set.
Self-made payment plugin :)
The scenario:
- customer starts the payment (payment_status: P)
- the vmpayment plugin communicatates with an API and got the response. If the payment was successful the payment_status will be C otherwise it will be X. I put the transaction identifier to the comment and it goes to the email too. It does work with no problem.
- when the shop admin changes the order status to Refunded (R) the plugin should start an API request and if it was successful it should store the API identifier of the Refund transaction as the comment of the order_history and also the email order changing email should contain this identifier
Cryptic but I think you are asking for your custom plugin to do something
when order status is changed - VM should fire the event
plgVmOnCancelPayment
As I have no idea how the api works - that is up to you to determine how success is handled in your new code.
This is part of the "updateStatusForOneOrder" function in orders.php
You should be able to add your API identifier as a comment - in the field "$inputOrder['comments']"
This will be passed to the relevant order history and the email
okay, I managed it.
Steps:
- I set the order status to R from the admin
- VM fires updateStatusForOneOrder()
- it fires my plgVmOnUpdateOrderPayment()
- I handle the API request and if I need, I call $modelOrder->updateStatusForOneOrder($order->virtuemart_order_id, $inputOrder, FALSE); with the specified comment. The third parameter should be false or VM will trigger plgVmOnUpdateOrderPayment() again, so I'll get an infinite loop
- The last of the function is return false; so VM won't finish the original updateStatusForOneOrder() and I won't get two #__virtuemart_order_histories entries