Custom field with logic hook calculation for Quotes not calculated:(

I have Suite CRM 7.7.9.

I want to have new field as a total product line amount that equals the quantity twice product unit price (by default there is no such field).
So I added product_value field as on the pic and the following files:

[root@crm AOS_Products_Quotes]# pwd
/var/www/html/crm/custom/modules/AOS_Products_Quotes
[root@crm AOS_Products_Quotes]# ls -l
total 8
drwxrws--- 3 apache apache  21 Feb  9 17:50 Ext
drwxrws--- 2 apache apache  28 Feb  9 17:50 language
-rwxr-xr-x 1 apache apache 225 Feb 18 20:58 logic_hooks.php
drwxrws--- 2 apache apache  81 Feb  9 18:04 metadata
-rwxr-xr-x 1 apache apache 299 Feb 20 10:21 product.php
[root@crm AOS_Products_Quotes]# more logic_hooks.php
<?php

$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Product Value', 'custom/modules/AOS_Products_Quotes/product.php', 'product', 'product_value');

?>
[root@crm AOS_Products_Quotes]# more product.php
<?php

//prevents directly accessing this file from a web browser
if (!defined('sugarEntry') ||!sugarEntry) die('Not A Valid Entry Point');

class product {
  function product_value ($bean, $event, $arguments) {
   $bean->product_value_c = $bean->$product_unit_price * $bean->product_qty;
  }
}

?>

The product_value_c is not calculated properly in a generated quote that uses this field. I have ā€œ0ā€ amount.

What else should I do to make this working?

You have it as an after_save. This should be a before_save. Having it as an after save you arenā€™t then saving the record thus the amount will always be zero.

I tested ā€˜before_saveā€™ ā€˜after_saveā€™, nothing and all the times the same problemā€¦

I also noticed two paths:
/var/www/html/crm/custom/modules/AOS_Products_Quotes/
/var/www/html/crm/modules/AOS_Products_Quotes

where should I put the logic_hooks file?

You should always be putting customisations in the custom directory. All looks correct at a glance except that the variable $product_unit_price is incorrect.
It should be:

$bean->product_value_c = $bean->product_unit_price * $bean->product_qty;

Thanks. It works :slight_smile:
It was a syntax error as you posted and I found another errorā€¦ I dindā€™t also know that I need to change aything in a quote and save to have affect in testing (when I printed the same saved quote to PDF after changing php files I had old valueā€¦).

Yeah, because I donā€™t believe Printing re-saves the Quote and therefore wouldnā€™t go through the logic_hook. Glad you got it sorted.

1 Like