How can i implement a logic hook

It works but after that i found that it fires whenever he find

status=“validated”

Whereas in my example I want it to trigger only when status changes

“x” status to “Validated”

Here is an example:
Capture5

Capture6

@turik
The variable has before value:

$bean->fetched_row->status

You can change the code in the following way

if ($bean->status == 'validated' && $bean->fetched_row->status <> $bean->status)
1 Like

@p.konetskiy I changed my code.
In this example it is triggered even if I modify the date and not the status :

@turik
Please, show your code.

@p.konetskiy This is my logic hooks:
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array[‘after_save’] = Array();
$hook_array[‘after_save’][] = Array(1, ‘status invoices Changes’, ‘custom/modules/AOS_Invoices/statusChange.php’,‘statusChange’, ‘statusInvoicesChanges’);
?>
my class :
<?php
class statusChange {
public function statusInvoicesChanges ($bean, $event, $arguments) {
// addition line:
$GLOBALS[‘log’]-> debug(get_class()." “. FUNCTION.” Status:\n ".print_r($bean->status,true));
if ($bean->status == ‘Validated’ && $bean->fetched_row->status <> $bean->status){
$GLOBALS[‘log’]-> debug(“Status has been changed”);
}
}
}
?>

@turik
I am sorry. I forgot that ‘fetched_row’ is array but not object. Please, change:

  • from:
$bean->fetched_row->status
  • to:
$bean->fetched_row['status']
1 Like

@p.konetskiy It works thanks.
I am moving forward in the work and needs can be change

How can i get ID of the invoice processed with my logic hook ?

Hey,
you should set up your IDE so that you’r able to debug your code, it will definitely help you a lot (and you’re probably looking for $bean->id).

2 Likes

There is a value in variable:

$bean->id

You can show all information about object but I recommend switch log level from ‘debug’ to 'fatal:

$GLOBALS[‘log’]->fatal(get_class()." “. FUNCTION.” Status:\n ".print_r($bean,true));

Look at documentation:


1 Like

Hi i want my logic hook fires when status =“paid” AND when date of payment change like this example :


So i did this and nothing happen

if($bean->status == ‘Paid’ && $bean->date_payment_c <> $bean->fetched_row[‘date_payment_c’]){}

what i’m missing ?

@turik
Now I sure that you know how to see values of variables in log file. You should print to log the variables and analyse.

1 Like

@p.konetskiy! Thanks i found the solution