turik
turik

Reputation: 47

logic hook fires only when $bean->status changes

I want to implement a Sugar Logic Hook that fires when invoice status change to 'Validated'.
This my logic hook :

<?php
$hook_version = 1; 
$hook_array = Array(); 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, 'status invoices Changes', '/var/www/html/suitecrm/modules/AOS_Invoices/AOS_LogicHooks.php','AOS_LogicHooks', 'statusInvoicesChanges'); 
?>

This is my action class:
<?php class AOS_LogicHooks {
 public function statusInvoicesChanges (SugarBean $bean, $event, $arguments){
if($bean->status == 'Validated' && $bean->fetched_row->status <> $bean->status){ 
$GLOBALS['log']->fatal("Status has been changed");
}}}
?>  


What do I missing?

Upvotes: 2

Views: 206

Answers (1)

mrbarletta
mrbarletta

Reputation: 922

Simple mistake we all do, fetched row is an Array so you cannot access the content as a property.

I just tested this and works fine! take a look:

<?php 

class AOS_LogicHooks
{
  public function statusInvoicesChanges(SugarBean $bean, $event, $arguments)
  {
    if ($bean->status == 'Validated' && !empty($bean->fetched_row) && $bean->fetched_row['status'] <> $bean->status) {
      $GLOBALS['log']->fatal("Status has been changed");
    }
  }
}

Upvotes: 2

Related Questions