创建发票和放大器;捕获的出货 [英] Creating Invoice & Capturing on Shipment
问题描述
我们已经得到了将定期创建订单发货一些API集成。
We've got some API integrations that will periodically create shipments for orders.
我想要做的就是创建一个观察者还可以创建一个相应的发票和放大器;捕捉付款创建这批货的时候。我有这个绑 sales_order_shipment_save_after
:
What I'd like to do is create an observer to also create an appropriate invoice & capture payment when this shipment is created. I have this tied to sales_order_shipment_save_after
:
public function autoInvoice($observer){
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$items = $shipment->getItemsCollection();
$qty = array();
foreach($items as $item)
$qty[$item['order_item_id']] = $item['qty'];
$invoice = Mage::getModel('sales/order_invoice_api');
$invoiceId = $invoice->create($order->getIncrementId(), $qty);
$invoice->capture($invoiceId);
}
(将code实际拍摄是有点幼稚,但我承担。)
(The code for the actual capture is somewhat naive, but bear with me.)
有什么奇怪的是,这个code的作品就好 - 装运创建,创建发票并标记为付费。但是,为了保持自己在地狱,并保留状态待定。
What's strange is that this code works just fine -- the shipment is created, the invoice is created and marked as 'Paid.' However, the order itself stays in limbo and retains a status 'Pending.'
展望进一步,订单本身的项目有正确的数量为订购和发货,但有开发票的数量没有上市。我认为这是什么引起的状态挂断。就好像在 qty_invoiced
在sales_order_item表得到某种原因而恢复。
Looking into it further, the items on the order itself have the correct quantities for both Ordered and Shipped, but there's no listing of the quantity Invoiced. I think this is what's causing the status hangup. It's as though the qty_invoiced
on the sales_order_item table is getting reverted somehow.
再次发票显示正确的项目,所以我很困惑在这里。
Again, the Invoice shows the right items, so I'm quite confused here.
任何想法?
推荐答案
这确实是一个很有趣的@bahoo。
This is indeed a very interesting one @bahoo.
也许尝试:
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$qty = array();
$invoice = Mage::getModel('sales/order_invoice_api');
$invoiceId = $invoice->create($order->getIncrementId(), $qty);
$invoice->capture($invoiceId);
这篇关于创建发票和放大器;捕获的出货的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!