VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on April 23, 2021, 17:20:55 PM

Title: change mail comments in plgVmOnUpdateOrderPayment
Post by: sandomatyas on April 23, 2021, 17:20:55 PM
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?
Title: Re: change mail comments in plgVmOnUpdateOrderPayment
Post by: pinochico on April 23, 2021, 18:06:34 PM
which payment plugin?
Title: Re: change mail comments in plgVmOnUpdateOrderPayment
Post by: AH on April 23, 2021, 19:35:16 PM
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.
Title: Re: change mail comments in plgVmOnUpdateOrderPayment
Post by: sandomatyas on April 28, 2021, 12:03:33 PM
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
Title: Re: change mail comments in plgVmOnUpdateOrderPayment
Post by: AH on April 28, 2021, 12:32:54 PM
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

Title: Re: change mail comments in plgVmOnUpdateOrderPayment
Post by: sandomatyas on June 03, 2021, 16:50:39 PM
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