Hi All,
I am having trouble with accessing data from the line items in a logic hook, the code I am using is below, when I call get_linked_beans I am being returned an empty Array even when modifying an already saved invoice. If anyone could give some insight into what might be going wrong that would be great.
Cheers,
Sam
function allocateTrees($bean, $event, $arguments)
{
if($bean->status == "Paid" && $bean->allocated_c != 1){
$line_items = $bean->get_linked_beans('aos_invoices_aos_product_quotes','AOS_Products_Quotes');
//load all line items relationships
foreach($line_items as $line_item)
{
$bean->free_text_c = $bean->free_text_c.$line_item;
$product = $line_item->get_linked_beans('aos_product_quotes_aos_products','AOS_Products');
if ($product->name == "Trees"){
//if the line item is a tree planting than we update the cumulative trees field.
$bean->cumulative_trees_c += $line_item->product_qty;
$bean->free_text_c = "Trees";
$product->current_count_c += $line_item->product_qty;
} else {
//if it isn't a tree assume 1 to 1 for tonnage
$bean->free_text_c = "Tonnage";
$product->current_count_c += $line_item->product_qty;
}
}
//set that the invoice has completed allocations.
$bean->description = $line_items[1]->id;
$bean->allocated_c = 1;
} elseif ($bean->allocated_c != 2) {
//invoice unpaid or already allocated - some other logic will be added here later.
$bean->allocated_c = 2;
}