Logic Hooks at creation record

I have created a logic hook to calculate a comission when the quotes is saved. But I realized that when the record is created event if the hook run after_save there are not data in the quote line products, but if once the records is created and I edit it when I save the hook work well.

Below the code
logic_hook.php under quotes module

$hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Commissions', 'custom/modules/AOS_Quotes/CommissionLoad.php','UpdateCommissionClass', 'UpdateCommissionFunction'); 

CommissionLoad.php

ini_set('display_errors', 1); 
	if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
	class UpdateCommissionClass 
	{ 


		static $already_ran = false;


		function UpdateCommissionFunction($bean, $event, $arguments) 
		{ 
			if(self::$already_ran == true) return;
			self::$already_ran = true; 

			$GLOBALS['log']->fatal('UpdateCommisionEntry called for Loads: '.$bean->id);

			
			$loadId = $bean->id;

			$sqlf = "SELECT  d.parent_id, d.product_id, d.product_list_price, d.deleted, c.fee_c  FROM aos_products_quotes d JOIN aos_products_cstm c ON d.product_id = c.id_c and d.parent_id = '$loadId' and c.fee_c = '1' and d.deleted = 0";

			$products = $bean->db->query($sqlf, true);


			
			$suma_total = 0;
			if ($products->num_rows <= 0)
				{
				echo 'No hay prodcutos';
			}else{
				$suma_total = 0;
				while ($prd = $products->fetch_array(MYSQLI_BOTH))
				{
					$suma_total = $prd['product_list_price'] + $suma_total;
				}
			}


			$driverId = $bean->assigned_user_id;

			$sql = "SELECT commission_c FROM users_cstm WHERE id_c = '$driverId'";
			$results = $bean->db->query($sql, true);
			$row = $bean->db->fetchByAssoc($results);
			$comision  = $row['commission_c'];
			$bean->fee_porcentage_c = $comision;

			$bean->comission_c = $suma_total * $comision / 100;
// write in log for verification *** temporal 
			$GLOBALS['log']->fatal('UpdateCommisionEntry called for Loads: '.$bean->comission_c);
			$GLOBALS['log']->fatal('UpdateCommisionEntry Valor Loads: '.$suma_total);
			$GLOBALS['log']->fatal('UpdateCommisionEntry Comission dvr: '.$comision);


		} 



	} 
?>

LOG when teh record is new

Tue Aug  2 16:09:31 2022 [3143519][1][FATAL] UpdateCommisionEntry called for Loads: e3a94152-e429-d20d-0eff-62e94ccc93b6
Tue Aug  2 16:09:31 2022 [3143519][1][FATAL] UpdateCommisionEntry called for Loads: 0
Tue Aug  2 16:09:31 2022 [3143519][1][FATAL] UpdateCommisionEntry Valor Loads: 0
Tue Aug  2 16:09:31 2022 [3143519][1][FATAL] UpdateCommisionEntry Comission dvr: 5.00

log when the recors is created and then updated

Tue Aug  2 16:10:54 2022 [3145117][1][FATAL] UpdateCommisionEntry called for Loads: e3a94152-e429-d20d-0eff-62e94ccc93b6
Tue Aug  2 16:10:54 2022 [3145117][1][FATAL] UpdateCommisionEntry called for Loads: 29
Tue Aug  2 16:10:54 2022 [3145117][1][FATAL] UpdateCommisionEntry Valor Loads: 580
Tue Aug  2 16:10:54 2022 [3145117][1][FATAL] UpdateCommisionEntry Comission dvr: 5.00

at this time the valor is updated.

Please take into consideration that module AOS_Quotes uses module AOS_Products_Quotes (AKA Line Items in Studio) to save products information.

You might want to check for the related Line Items from your logic hook in order to catch the values

Thanks for your quick answer.
Do you mind elaborate more the answer? What do you mean is that the logic-hook should run in the AOS_Products_quotes instead AOS_quotes? I afaid that under this module the asisnged id is not accessible. I mean the porcion where the program ask for the commission in the table users_ctsm where it needs the userId.

Sorry for my late response. It’s hard to squeeze some time to respond sometimes.

You access the quote by using fields parent_type, parent_id from aos_products_quotes

and use group_id to reach module

aos_line_item_groups