为部分订单开具发票;总数未更新
在我们的订单流程中,可以发送部分订单的发票。因此,当运送几个订单行时,还必须发送发票。
为了实现这一点,我使用以下代码:
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($items);
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$invoice->sendEmail();
$invoice->setEmailSent(true);
$invoice->save();
其中 $items
变量是一个数组,其中包含订单 ID 和要开具发票的产品数量。
创建的发票显示要开具发票的正确产品,但不知何故总计未更新。总计仍然是完整订单的总计,而不是部分发票的总计。
我可能必须更新或重新计算总数,但找不到正确的代码来强制更新。
周围有谁可以引导我走向正确的方向吗?
In our order proces it is possible to send an invoice for a partial order. So when a couple of order lines are being shipped, an invoice have to be send also.
To make this possible I use this code:
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($items);
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$invoice->sendEmail();
$invoice->setEmailSent(true);
$invoice->save();
Where the $items
variable is an array containing the order ids and the amount of products to be invoiced.
The created invoice shows the correct products to be invoiced, but somehow the totals aren't updated. The totals still are the totals of the complete order, instead of the partial invoice.
I probably have to update or recalculate the totals but can't find the right code to force the update.
Anyone around who can put me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,看来我已经发现问题了。上述功能可在管理员界面中手动执行。上面所附的代码我只能通过更改 Magento 的核心文件来工作。
如果将 Mage_Sales_Model_Service_Order 的第 103 行从
continue;
更改为$qty = 0;
,该功能将起作用。简而言之,这就是发生的事情。继续时,第二行项目不会添加到发票中,发票认为当前项目是整个订单的最后一个项目,因此需要对完整的未清金额开具发票。就我而言,我确实想要开具发票的发票和我不想开具发票的行。
我已将其作为 Magento 问题列表中的问题提交。
Well, it seems I have found the problem. The functionality as described above works manually executing it in the administrator interface. The code as enclosed above I only got to work by changing a core file of Magento.
If you change line 103 of Mage_Sales_Model_Service_Order from
continue;
to$qty = 0;
the functionality works.In short, this is what happens. With continue the second row item isn't added to the invoice which the invoice makes thinks the curren item is the last item of the whole order and therefore needs to invoice the complete outstanding amount. In my case the invoice I did want to invoice and the row I didn't want to invoice.
I've submitted it as issue on the Magento issue list.
今天我就遇到了这个问题,但我找到了一种更优雅的方法来解决它,而无需编辑核心。解决方案是通过我们不想开发票的产品,数量为 0。
通过这种方式,您在核心中更改的代码的行为将与您的解决方案中的行为完全相同:)
举个例子,如果我的订单中有 2 个产品:
传递此数组:
将强制此代码:
与您的解决方案中的行为完全相同,因此您不必编辑核心代码。
希望它有帮助:)
Today I faced with exactly this problem, but I found a more elegant way to solve it without editing the core. The solution is to pass the products that we don't want to invoice, with 0 quantity.
In this way, the code you changed in core will act exactly like in your solution :)
As an example if I have 2 products in my order:
passing this array:
will force this code:
to act exactly like in your solution, so you don't have to edit core code.
Hope it helps :)
好的 - 花了我一点时间,但现在我看到了如何正确创建数组。
这将创建正确的发票。
OK - took me a bit, but now I see how to correctly create the array.
This creates a proper invoice.