从 Mage_Sales_Model_Order_Invoice 对象获取发票 ID
我正在为 sales_order_invoice_register 事件编写一个观察者,我想获取刚刚保存的发票号码。我找不到用于检索该 ID 的函数,这些注释的调用都不起作用。有什么想法吗? 这里是代码
public function foobar($observer){
$order = $observer->getEvent()->getOrder();
$id_order = $order->getRealOrderId();
$id_invoice = $observer->getEvent()->getInvoice(); // the Mage_Sales_Model_Order_Invoice object
//$id_invoice = $id_invoice->getId();
//$id_invoice = $id_invoice->getIncrementId();
//$id_invoice = $id_invoice->getInvoiceId();
//$id_invoice = $id_invoice->getRealIncrementId();
//$id_invoice = $id_invoice->getData('invoice_id');
谢谢!
I'm writing an observer for the sales_order_invoice_register event, I'd like to get the invoice number that has just saved. I can't find the function for retrieving that ID, none of those commented calls works. Any idea?
Here the code
public function foobar($observer){
$order = $observer->getEvent()->getOrder();
$id_order = $order->getRealOrderId();
$id_invoice = $observer->getEvent()->getInvoice(); // the Mage_Sales_Model_Order_Invoice object
//$id_invoice = $id_invoice->getId();
//$id_invoice = $id_invoice->getIncrementId();
//$id_invoice = $id_invoice->getInvoiceId();
//$id_invoice = $id_invoice->getRealIncrementId();
//$id_invoice = $id_invoice->getData('invoice_id');
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是不久前的事,但如果有人仍然需要帮助,希望以下内容会有用。
进入观察者方法后,使用以下代码获取发票 ID。
您可以查看 Mage 数据库中的 sales_flat_invoice 表(ID 是名称为“entity_id”的第一个字段)。一旦您拥有了 $invoice 对象(与从 Varien_Object 类继承的任何其他对象类似),您就可以使用 Magento 的
getData()
方法来访问属性值。另外,可能需要查看不同的事件...根据 Mage 文档, sales_order_invoice_register 事件返回“未知”。尝试使用上述代码的
sales_order_invoice_pay
事件。I know this was a while ago, but in case someone still needs help on this, hopefully the following will be of use.
Once in your observer method, use the following code to get invoice ID.
You can check out the sales_flat_invoice table in the Mage db (ID is the first field with the name 'entity_id'). Once you have the $invoice object, similar to any other object that inherits from the Varien_Object class, you can use Magento's
getData()
method to access attribute values.Also, need to look at a different event possibly... the sales_order_invoice_register event returns "unknown" according to Mage docs. Try the
sales_order_invoice_pay
event for the above code.您应该在 config.xml 和observer.php 中使用事件“sales_order_invoice_save_after”:
$observer->getEvent()->getInvoice();
You should use the event "sales_order_invoice_save_after" in the config.xml and in your observer.php :
$observer->getEvent()->getInvoice();