For Joomla 3 I used plgVmCouponUpdateOrderStatus, and worked perfectly.
On Joomla 4 the events whose name does not start with "on" no longer work. I tried to find in VM 4.0.12 I could use instead to catch the order status change event (I need that to trigger actions in a custom built component) but no luck so far. Any hint, idea or solution is highly appreciated!
plgVmOnUpdateOrderPayment ?
Thanks, will try your tip obviously, the problem seemingly is not the triggering event - the one I used is still there in the code of VM - but this:
Quote"On Joomla 4 the events whose name does not start with "on" no longer work."
I did not marked it correctly to be obvious, but the sentence is from this page: https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4#Plugins_.28Events.29
Yup, as I suspected. Nothing. Not even an error message. Anyways, the client needs the event to be triggered when the order is confirmed by shop admin :(
Works fine for me
QuoteAnyways, the client needs the event to be triggered when the order is confirmed by shop admin
That is what I use it for
function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
$status = $this->params->get('status', 'C');
$status_array = explode(',',$status);
if(in_array($data->order_status, $status_array)){
// do something
}
}
I have this:
function plgVmOnUpdateOrderPayment ($data,$old_order_status){
Factory::getApplication()->enqueueMessage('Royalty check on UpdateOrderStatus', 'message');
vmdebug('Royalty check on UpdateOrderStatus '.$data->order_status);
// .... and some other code
}
I get nothing, The plugin isn't triggered. The code works on J3...
Quote from: GJC Web Design on April 09, 2023, 18:41:07 PM
Works fine for me
That is what I use it for
On Joomla 4/VM 4.0.12??
yep -- exactly the code above in a VMCustom plugin triggered by the order going to Confirmed
Can you please share the full plugin code??? I am doing something wrong somewhere, and can't find out what... :(
I have pasted the relevant code here.. the rest has nothing to do with the triggering
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0" type="plugin" group="vmcustom" method="upgrade">
<name>Order Save for VirtueMart</name>
<author>GJC</author>
<creationDate>April 2023</creationDate>
<copyright>www.GJCWebdesign.com</copyright>
<license>GNU General Public License</license>
<authorEmail>webmaster@gjcwebdesign.com</authorEmail>
<authorUrl>https://www.gjcwebdesign.com</authorUrl>
<version>2.2.0</version>
<description>Virtuemart Plugin to save order details incl. images for each order. Needs the GJC VMReview 3.0.0 component.</description>
<files>
<filename plugin="ordersave">ordersave.php</filename>
<folder>language</folder>
</files>
<config>
<fields name="params" addpath="/administrator/components/com_virtuemart/elements">
<fieldset name="basic">
<field name="status" type="vmorderstate" scope="com_virtuemart" default="C" size="3"
label="VMCUSTOM_ORDERSAVE_STATUS_LABEL" description="VMCUSTOM_ORDERSAVE_STATUS_DESC"/>
<field
name="noreg"
type="radio"
default="1"
label="VMCUSTOM_ORDERSAVE_NOREG_LABEL"
description="VMCUSTOM_ORDERSAVE_NOREG_DESC">
<option
value="0">JNO</option>
<option
value="1">JYES</option>
</field>
<field
name="nameuse"
type="radio"
default="1"
label="VMCUSTOM_ORDERSAVE_NAMEUSE_LABEL"
description="VMCUSTOM_ORDERSAVE_NAMEUSE_DESC">
<option
value="1">VMCUSTOM_ORDERSAVE_NAMEUSE2</option>
<option
value="2">VMCUSTOM_ORDERSAVE_NAMEUSE3</option>
</field>
<field
name="imagehandle"
type="radio"
default="0"
label="VMCUSTOM_ORDERSAVE_IMAGEH_LABEL"
description="VMCUSTOM_ORDERSAVE_IMAGEH_DESC">
<option
value="0">VMCUSTOM_ORDERSAVE_IMAGEH1</option>
<option
value="1">VMCUSTOM_ORDERSAVE_IMAGEH2</option>
<option
value="2">VMCUSTOM_ORDERSAVE_IMAGEH3</option>
</field>
<field
name="imagefolder"
type="text"
size="40"
default="/media/ordersave/"
label="VMCUSTOM_ORDERSAVE_IMGF_LABEL"
description="VMCUSTOM_ORDERSAVE_IMGF_DESC" />
<field
name="debug"
type="radio"
default="0"
label="VMCUSTOM_ORDERSAVE_DEBUG_LABEL"
description="VMCUSTOM_ORDERSAVE_DEBUG_DESC">
<option
value="0">JNo</option>
<option
value="1">JYes</option>
</field>
</fieldset>
</fields>
</config>
</extension>
<?php
/*------------------------------------------------------------------------
# ordersave.php v2.1.8
# ------------------------------------------------------------------------
# @license - GNU/GPL http://www.gnu.org/copyleft/gpl.html
# Author: GJC Web Design
# Websites: https://www.gjcwebdesign.com
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');
if (!class_exists('vmPSPlugin'))
require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig ();
class plgVmCustomOrdersave extends vmPSPlugin {
// instance of class
public static $_this = false;
function __construct(& $subject, $config) {
parent::__construct($subject, $config);
}
function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
$app = JFactory::getApplication();
if (!$app->isClient('administrator')){
}
$status = $this->params->get('status', 'C');
$status_array = explode(',',$status);
if(in_array($data->order_status, $status_array)){
//Check if already saved
$db = JFactory::getDbo();
$query = '';
$db->setQuery($query);
$already = $db->loadResult();
if(empty($already)){
$result = $this->plgVmOrdersave($data,$old_order_status );
}else{
vmAdminInfo("Order already saved to GJC Reviews table");
return;
}
if ($result == 'saved') {
vmAdminInfo("Order saved to GJC Reviews table");
}elseif ($result == 'noreg') {
vmAdminInfo("User is not registered - order not saved to GJC Reviews");
}else{
vmAdminInfo("Order save to GJC Reviews table didn't work :( ");
}
}else{
#print 'Debug Line '.__LINE__.' $status_array <pre>'; print_r ($status_array); print "</pre><br />\n";die();
}
}
}
Thank you!! Will get back to you as I test it.
Bingo!!! Worked, thank you!