VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: nicoletta on August 31, 2022, 11:30:18 AM

Title: how to set a trigger on order confirmed
Post by: nicoletta on August 31, 2022, 11:30:18 AM
Hello,
I use VM 4 on Joomla 3.10.

I would need to run a script every time an order is confirmed (by direct payment or by change of status in the administrator).

I understood that I should use a custom plugin but I don't know how to write it and how to call it.

Is anyone kind enough to help me?
Title: Re: how to set a trigger on order confirmed
Post by: GJC Web Design on September 01, 2022, 10:03:02 AM
write either a system or vmcustom plugin and use

class plgVmCustomYourname extends vmPSPlugin {

    function __construct(& $subject, $config) {
   parent::__construct($subject, $config);   
    }

 
   function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
// your code here

       }
}

Title: Re: how to set a trigger on order confirmed
Post by: nicoletta on September 02, 2022, 09:56:44 AM
Thank you for the reply.
I made a vmcustom plugin like this, just to see if it was properly intercepted:


class subsorderconfirm extends vmPSPlugin {

    function __construct(& $subject, $config) {
        parent::__construct($subject, $config);
    }

   function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
            echo "ok";
            die();
       }
}


but nothing happens when the order status changes to paid.
Where am I wrong?
Title: Re: how to set a trigger on order confirmed
Post by: GJC Web Design on September 02, 2022, 11:53:48 AM
afaik you must stick to the Joomla naming conventions

class plgVmCustomYourname
Title: Re: how to set a trigger on order confirmed
Post by: nicoletta on September 02, 2022, 12:40:41 PM
Great! It works!

I also ask you if you know which trigger I have to call during registration, to take user data and also save them in a custom table.

Thank you!
Title: Re: how to set a trigger on order confirmed
Post by: nicoletta on September 02, 2022, 12:48:07 PM
or better, the trigger after BT address save...
Title: Re: how to set a trigger on order confirmed
Post by: GJC Web Design on September 02, 2022, 12:58:13 PM
Just search the VM models for triggers

search   plgVm   
 
in the user.php prob   plgVmOnBeforeUserfieldDataSave
Title: Re: how to set a trigger on order confirmed
Post by: nicoletta on September 02, 2022, 13:23:40 PM
If I understand, in the same way I create another vmcustom plugin like this:

class plgVmCustomMysyncusers extends vmPSPlugin {

    function __construct(& $subject, $config) {
        parent::__construct($subject, $config);
    }

    function plgVmOnBeforeUserfieldDataSave (&$valid, $juserid, &$data, $user) {
      echo "OK";

        die();
    }

}


but it don't work
Where am I wrong now?
Title: Re: how to set a trigger on order confirmed
Post by: Studio 42 on September 02, 2022, 14:33:47 PM
Do not use a customfield plugin
plgVmCustomXXXXX
But a Joomla system plugin to be sure the plugin is always triggered
plgVmOnBeforeUserfieldDataSave is called only for vm userfields
plgVmOnUpdateOrderPayment  is only for payment plugins
So you are not sure it get triggerred in all Vm releases
Using a plgSystemXXX in the plugin/system/XXX folder work always


defined('_JEXEC') or die;


jimport('joomla.plugin.plugin');


class plgSystemXXX extends JPlugin
{

   function plgVmOnUpdateOrderPayment ($data,$old_order_status) {
            echo "ok";
            die();
       }

    function plgVmOnBeforeUserfieldDataSave (&$valid, $juserid, &$data, $user) {
      echo "OK";


        die();
    }
}


This should work because you do not need external Virtuemart datas to be set your plugin properties in your case.
Title: Re: how to set a trigger on order confirmed
Post by: nicoletta on September 02, 2022, 15:01:08 PM
It works!!!!
I don't know how to thank you!

So now I just have to write my functions correctly.
I hope I no longer need it.

Thanks so much again