I've got a basic observer function to grab all of the gift items in an order and return them:
public function invoiceGiftCards($observer){
$order = $observer->getEvent()->getOrder();
// get all items
$gift_cards = $order->getItemsCollection(array('giftcard'));
Mage::log('getSize(): ' . $gift_cards->getSize());
// code to auto-create invoice
...
}
Tied to this event:
<sales_model_service_quote_submit_after>
<observers>
<company_invoice_gift_cards>
<type>singleton</type>
<class>Company_Module_Model_Observer</class>
<method>invoiceGiftCards</method>
</company_invoice_gift_cards>
</observers>
</sales_model_service_quote_submit_after>
But what I'm finding is, that collection from the function returns empty every time. Even in orders that clearly have gift cards in them:
2011-06-25T01:33:38+00:00 DEBUG (7): getSize(): 0
Even more strange, if I run that same getItemsCollection(array('giftcard'))
on an arbitrary order in the system (as part of a controller), it works fine.
It's like things haven't finished saving yet. Is there another observer I should try? (I also tried checkout_submit_all_after
for grins, no dice).
There seems to be something with the order of operations when transactions like orders take place. I've ran into a similar problem before: Creating Invoice & Capturing on Shipment You can see in my comments that my solution there is less than ideal, but I don't know what else to do.
If anyone could shed some light on this for me, I would greatly appreciate it. Thank you.