after_relationship_add - Order Process

Hi everyone.

I have written a logichook on "after_relationship_add". What this does is calculates the split % of the added item. For example I have 1 Opportunity for £100, I have 10 Revenue Line Items linked, so the split on each item is 10%.

If I add an 11th item, the split should become 9.09%. However when checking the "count" of related records, it seems to differ on whether I've added an existing Revenue Line Item or an Existing One.

If I add the item, running the code returns the correct amount, if I create a new one, it shows one too few (The new record is missing).

The code example is:

$link = "ccs_clientcostsplit_revenuelineitems";
if ($bean->load_relationship($link)) {
//Fetch related record IDs
$linkedSplits = $bean->$link->get();
$splitPercent = 100 / (count($linkedSplits)); 
foreach($linkedSplits as $split)
{
	$linkedSplitBean = BeanFactory::retrieveBean("CCS_ClientCostSplit",$split, array('disable_row_level_security' => true));
	$linkedSplitBean->percent_split = $splitPercent;
	$linkedSplitBean->save();
}

I'm doing this on an after_relationship_add module hook, but it seems to differ. I've tried checking if $bean->id is there, but it seems the record is created but not linked on the point of after_relationship_add.

Any help at all would be great.

Thanks,

Daniel

Parents Reply Children
No Data