Page 1 of 1

Calculated total fields not working if marked read only

Posted: 2019-05-12 08:02
by kevinm
Just in case anyone else is having a problem with populating calculated fields from hooks, this might save some time...

This won't work if the Total fields 'Read Only' checkbox is ticked:

Code: Select all

function tablename_before_update(&$data, $memberInfo, &$args){
     
    // calculate total after applying discount
    $data['total'] = $data['subtotal'] * (1 - $data['discount'] / 100);
     
    // calculate total after applying sales tax 
    $data['total'] = $data['total'] * (1 + $data['sales_tax'] / 100); 
     
    return TRUE;
}
The only way I found to do it was through a seperate SQL update statement.