提交订单后希望为礼品卡购买开具发票

发布于 11-17 06:06 字数 1405 浏览 2 评论 0原文

我有一个基本的观察者函数来获取订单中的所有礼品并将其返回:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强者自强2024-11-24 06:06:21

报价是订单之前的内容,我猜测在报价相关事件发生时订单尚不存在或不完整。也许更相关的行动时间是 sales_convert_quote_to_ordersales_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 or sales_order_save_after.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文