Paypal IPN 的 Magento 事件将订单标记为正在处理
我正在开发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一段时间的努力后,我最终通过覆盖 Mage_Sales_Model_Order_Payment 中的 _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.
This is thanks to the answer to another question: https://stackoverflow.com/a/5024475/602734
Hopefully this helps someone!
如果有人像我一样偶然发现这个问题,那么观察者会按照最初的要求这样做;
checkout_onepage_controller_success_action
这仅返回订单 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;
and you see that the order status is 'processing' and the payment is aproved (or not).