从 Mage_Sales_Model_Order_Invoice 对象获取发票 ID

发布于 2024-12-13 17:12:13 字数 1084 浏览 4 评论 0原文

我正在为 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 技术交流群。

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

发布评论

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

评论(2

热情消退 2024-12-20 17:12:14

我知道这是不久前的事,但如果有人仍然需要帮助,希望以下内容会有用。

进入观察者方法后,使用以下代码获取发票 ID。

$invoice = $observer->getEvent()->getInvoice();
$invoice_id = $invoice->getData('entity_id');  // or you could also use ->getEntityId();

您可以查看 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.

$invoice = $observer->getEvent()->getInvoice();
$invoice_id = $invoice->getData('entity_id');  // or you could also use ->getEntityId();

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.

染墨丶若流云 2024-12-20 17:12:14

您应该在 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();

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