Paypal IPN 的 Magento 事件将订单标记为正在处理

发布于 2024-12-18 07:46:37 字数 1005 浏览 4 评论 0原文

我正在开发 Magento (1.4 CE) 的扩展,一旦订单付款就需要触发该扩展。我无法找到一个事件来挂钩,当 Paypal IPN(Paypal 标准)完成其工作时会触发该事件。

我尝试过使用 sales_order_invoice_save_after 和 sales_order_invoice_register 事件,但这两个事件似乎都不是由 Paypal IPN 响应触发的。

我现在尝试使用 sales_order_save_after 事件来检测订单何时进入“处理”状态,如下所示:

class Lightbulb_Blastramp_Model_Observer {

    public function sendOrderToBlastramp(Varien_Event_Observer $observer) {

        Mage::log('Start' . "\n\n", null, 'blastramp.log');

        $order = $observer->getEvent()->getOrder(); // get order data

        // make sure the order is in the processing state
        if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING) {
            Mage::log('Not processing, return.' . "\n\n", null, 'blastramp.log');
            return $this;
        }
        // order has reached "processing" state, do stuff...
    }
}

从日志文件中我可以看到,当订单最初以“付款待处理”状态创建时,我的代码被触发,但当它进入“处理”状态时不会被触发。当订单进入 Paypal IPN 设置的“处理”阶段时,是否有一些我可以挂钩的事件会触发?

干杯

I'm working on an extension for Magento (1.4 CE) that needs to be triggered once an order has been paid for. I'm having trouble finding an event to hook in to that will trigger when Paypal IPN (Paypal Standard) has done its thing.

I've tried using the sales_order_invoice_save_after and sales_order_invoice_register events, but neither of these seem to be triggered by a Paypal IPN response.

I'm now trying to use the sales_order_save_after event to detect when the order enters the "processing" status, like so:

class Lightbulb_Blastramp_Model_Observer {

    public function sendOrderToBlastramp(Varien_Event_Observer $observer) {

        Mage::log('Start' . "\n\n", null, 'blastramp.log');

        $order = $observer->getEvent()->getOrder(); // get order data

        // make sure the order is in the processing state
        if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING) {
            Mage::log('Not processing, return.' . "\n\n", null, 'blastramp.log');
            return $this;
        }
        // order has reached "processing" state, do stuff...
    }
}

From the log files I can see that my code is triggered when the order is initially created with the "payment pending" state, but does not get triggered when it moves to the "processing" state. Is there some event I can hook in to that will trigger when an order hits the "processing" stage as set by Paypal IPN?

Cheers

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

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

发布评论

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

评论(2

清欢 2024-12-25 07:46:37

经过一段时间的努力后,我最终通过覆盖 Mage_Sales_Model_Order_Payment 中的 _isCaptureFinal($amount) 方法取得了成功。

例如。

class Lightbulb_Blastramp_Model_Order_Payment extends Mage_Sales_Model_Order_Payment {
    public function _isCaptureFinal($amount) {
        // do things here
        return parent::_isCaptureFinal($amount);
    }
}

这要归功于另一个问题的答案:https://stackoverflow.com/a/5024475/602734

希望这会有所帮助有人!

After struggling with this for a while, I eventually had success with this by overriding the _isCaptureFinal($amount) method in Mage_Sales_Model_Order_Payment.

eg.

class Lightbulb_Blastramp_Model_Order_Payment extends Mage_Sales_Model_Order_Payment {
    public function _isCaptureFinal($amount) {
        // do things here
        return parent::_isCaptureFinal($amount);
    }
}

This is thanks to the answer to another question: https://stackoverflow.com/a/5024475/602734

Hopefully this helps someone!

鸠魁 2024-12-25 07:46:37

如果有人像我一样偶然发现这个问题,那么观察者会按照最初的要求这样做;

checkout_onepage_controller_success_action

这仅返回订单 ID,因此;

$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);

您会看到订单状态为“正在处理”并且付款已批准(或未批准)。

In case anyone stumbled upon this question like i did, an observer that does this as was originally requested;

checkout_onepage_controller_success_action

This returns just the order id, so;

$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);

and you see that the order status is 'processing' and the payment is aproved (or not).

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