提交订单后希望为礼品卡购买开具发票
我有一个基本的观察者函数来获取订单中的所有礼品并将其返回:
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
...
}
与此事件相关:
<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>
但我发现,函数中的集合每次都返回空。即使订单中明确包含礼品卡:
2011-06-25T01:33:38+00:00 DEBUG (7): getSize(): 0
更奇怪的是,如果我运行相同的 命令getItemsCollection(array('giftcard'))
在系统中的任意订单上(作为控制器的一部分),它工作得很好。
好像事情还没有完成保存。我还应该尝试其他观察者吗? (我还尝试了 checkout_submit_all_after
微笑,没有骰子)。
当诸如订单之类的交易发生时,操作顺序似乎存在一些问题。我之前遇到过类似的问题:创建发票和发票在发货时捕获 您可以在我的评论中看到我的解决方案不太理想,但我不知道还能做什么。
如果有人能为我阐明这一点,我将不胜感激。谢谢。
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.
报价是订单之前的内容,我猜测在报价相关事件发生时订单尚不存在或不完整。也许更相关的行动时间是
sales_convert_quote_to_order
或sales_order_save_after
。The quote is what comes before the order, I would guess that at the time of a quote-related event the order does not yet exist, or is incomplete. Perhaps a more relevant time to act would be
sales_convert_quote_to_order
orsales_order_save_after
.