在以编程方式在Magento中创建贷项凭证时,我正试图弄清楚如何消除运费。我使用的其中一个参考是Mage_Sales_Model_Order_Creditmemo
类,特别是setShippingAmount
(例如$this->setData('shipping_amount', 0)
)。事实上,当我尝试使用它时,运输&处理行已从Credit Memo Totals框中完全删除,但无论如何计算运费......
我注意到的另一个有趣的事情是:如果我在$data array
(例如$creditmemo = $service->prepareCreditmemo($data)
)中为'adjust_negative' var指定了值,则会正确计算退款总额在主屏幕上,但如果我点击实际贷记凭证并查看总计分类,则调整费为0.00,并且贷记凭证或主要订单上的信息视图中的总金额未更改(总退款金额为根据我的代码错了!)。
非常感谢任何帮助!
$orderItem = $order->getItemsCollection()->getItemByColumnValue('sku', 'somesku');
$data = array(
'qtys' => array($orderItem->getId() => 1
),
'shipping_amount' => '0',
'adjustment_positive' => '0',
'adjustment_negative' => '10.50'
);
$service = Mage::getModel('sales/service_order', $order);
$creditmemo = $service->prepareCreditmemo($data);
//$refundToStoreCreditAmount = '3.00';
$refundToStoreCreditAmount = max(
$refundToStoreCreditAmount, min($creditmemo->getBaseCustomerBalanceReturnMax(), 0));
$refundToStoreCreditAmount =
$creditmemo->getStore()->roundPrice($refundToStoreCreditAmount);
//$this->setData('base_shipping_amount', $amount);
//
//$amount = $this->getStore()->roundPrice(
//$amount*$this->getOrder()->getStoreToOrderRate()
$creditmemo->setBaseCustomerBalanceTotalRefunded($refundToStoreCreditAmount);
//$creditmemo->setData('shipping_amount', 0);
//$creditmemo->setData('base_shipping_amount', 0);
$refundToStoreCreditAmount =
$creditmemo->getStore()->roundPrice(
$refundToStoreCreditAmount*$order->getStoreToOrderRate());
$creditmemo->setBsCustomerBalTotalRefunded($refundToStoreCreditAmount);
$creditmemo->setCustomerBalanceRefundFlag(true);
$creditmemo->setPaymentRefundDisallowed(true);
$creditmemo->register();
/*
$shipping = 0;
$creditmemo->setShippingAmount($shipping);
$creditmemo->setBaseShippingAmount($shipping);
$creditmemo->setShippingInclTax($shipping);
$creditmemo->setBaseShippingInclTax($shipping);
*/
//$creditmemo->setGrandTotal($creditmemo->getGrandTotal()+$shipping);
//$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal()+$baseShipping);
//$orderCreditMemoStatusCode = Mage_Sales_Model_Order::STATE_COMPLETE;
$saveTransaction = Mage::getModel('core/resource_transaction')->addObject(
$creditmemo )->addObject ( $order )->save ();
$creditmemo->setEmailSent(true);
try {
Mage::getModel('core/resource_transaction')
->addObject($creditmemo)
->addObject($order)
->save();
// send email notification
$creditmemo->sendEmail($notifyCustomer, ($includeComment ? $comment : ''));
}
catch (Mage_Core_Exception $e) {
print_r('data_invalid', $e->getMessage());
}
答案 0 :(得分:2)
我明白了。我尝试在后端手动创建贷记凭证,在我从我的脚本创建的订单上,并且遇到了同样的问题(我无法删除/清除运费金额)。我发现通过在创建订单时添加$ order-> setBaseShippingAmount('somevalue')(我已经在使用$ order-> setShippingAmount()),它允许我在创建贷项通知单后删除运费!希望这有助于某人...