Trigger on order creation

Hi,

I’m currently trying to implement my own trigger to Dolibarr that would automatically validate an incoming order, if it’s not already validated.

My trigger is detected and active, but I’m struggling to know what class/methods call and with which arguments.

I found on the Dolibarr doc the classe Commande which has a method “valid” : Dolibarr: htdocs/commande/class/commande.class.php Source File

I’m trying to valid my incoming order by simply putting in my trigger “$object.valid(…)” since $object is from that class but the method requires a User.

I suppose they ask for a user that would have the right to validate an order, but how could I fetch it ?

Thank you for your help or any other advice !

That’s right, you need a user with the required rights. This user is also recorded as being the one who did the validation. If you create a user for this purpose (and set its rights accordingly), you can fetch it like this:

require_once DOL_DOCUMENT_ROOT.‘/user/class/user.class.php’;
$user = new User($this->db);
$user_id = $user->findUserIdByEmail(“user@example.com”);
$user->fetch($user_id);

BTW all class descriptions are available under this link: https://doxygen.dolibarr.org/ (if you did not come across this already).

Thank you, I managed to achieve what I wanted to do with your help.
Another thing I needed to add is : $user->getrights(), which loads the rights of the user.