我正在尝试以编程方式创建一个 Magento Credit Memo,但 Magento 向我展示了一个总计为零的贷项通知单。
$incrementID = "100000016";
$orderMagento = Mage::getModel('sales/order')->loadByIncrementId($incrementID);
$convertOrder = new Mage_Sales_Model_Convert_Order ();
$creditmemo = $convertOrder->toCreditmemo ( $orderMagento );
$items = $orderMagento->getAllItems();
foreach ( $items as $item ) {
$_eachCreditMemoItem = $convertOrder->itemToCreditmemoItem ( $item );
$_eachCreditMemoItem->setQty ($item->getQtyInvoiced());
$_eachCreditMemoItem->register ();
$creditmemo->addItem ( $_eachCreditMemoItem );
$totalQty += $item->getQtyInvoiced ();
}
$creditmemo->refund();
$creditmemo->setTotalQty ( $totalQty );
$creditmemo->collectTotals();
$orderCreditMemoStatusCode = Mage_Sales_Model_Order::STATE_CLOSED;
$orderCreditMemoStatusComment = $comment;
$saveTransaction = Mage::getModel('core/resource_transaction')->addObject ($creditmemo )->addObject ( $orderMagento )->save ();
$orderMagento->addStatusToHistory ( $orderCreditMemoStatusCode, $orderCreditMemoStatusComment, false );
$orderMagento->save ();
我在 StackOverflow 中找到了这段代码,我正在尝试使用它,但它也不起作用。
为什么总数没有更新?哪个是创建它的正确方法?
谢谢