News:

Support the VirtueMart project and become a member

Main Menu

change mail comments in plgVmOnUpdateOrderPayment

Started by sandomatyas, April 23, 2021, 17:20:55 PM

Previous topic - Next topic

sandomatyas

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

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

AH

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 4.4.5
php 8.1

sandomatyas

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

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 4.4.5
php 8.1

sandomatyas

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