How to get the related line items to an Invoice?


I’m trying to get the line items that are related to an invoice.

Logic hook for AOS_Invoices:

$hook_array['after_save'][] = Array(1, 'DecrementProductStock', 'custom/modules/AOS_Invoices/Decrement.php', 'product', 'decrement_stocks');

And then in the class product:

function decrement_stocks ( &$bean, $event, $arguments)
			// Tried them all, only with empty arrays as return values
			// $oInvoice->load_relationship('aos_products_quotes');
			// $aProductQuotes = $oInvoice->aos_products_quotes->getBeans();
			$aProductQuotes = $bean->aos_line_item_groups->get();
			$aLineItemGroups = $bean->get_linked_beans('aos_line_item_groups', 'AOS_Line_Item_Groups');

Everytime I get an empty array.
So if I create and save an invoice, in the after_save logic hook, the invoice including the relationships, should have already been saved, right?
How can I access the line items?

I don’t know the answer, but I can try helping you find it…

There is code you can copy to do this:

Drop all that stuff to generate HTML and you’re left with the necessary database queries.

You might also learn something from browsing the database schema:


Good luck. Please come back here and share your solution, if you can.