Author Topic: change mail comments in plgVmOnUpdateOrderPayment  (Read 1697 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 330
change mail comments in plgVmOnUpdateOrderPayment
« 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?

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1242
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: change mail comments in plgVmOnUpdateOrderPayment
« Reply #1 on: April 23, 2021, 18:06:34 pm »
which payment plugin?
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3491
  • VirtueMart Version: 3.8.9
Re: change mail comments in plgVmOnUpdateOrderPayment
« Reply #2 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.
Regards
A

Joomla 3.9.27
php 7.4

sandomatyas

  • Jr. Member
  • **
  • Posts: 330
Re: change mail comments in plgVmOnUpdateOrderPayment
« Reply #3 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

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3491
  • VirtueMart Version: 3.8.9
Re: change mail comments in plgVmOnUpdateOrderPayment
« Reply #4 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

Regards
A

Joomla 3.9.27
php 7.4

sandomatyas

  • Jr. Member
  • **
  • Posts: 330
Re: change mail comments in plgVmOnUpdateOrderPayment
« Reply #5 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