在以编程方式在 Magento 中创建贷项通知单时,我正在努力弄清楚如何消除运费。我使用的参考之一是Mage_Sales_Model_Order_Creditmemo
类,特别是setShippingAmount
(例如$this->setData('shipping_amount', 0)
)。事实上,当我尝试使用它时,运输和处理行已完全从贷项凭单总计框中删除,但无论如何都会计算运输......
我注意到的另一件有趣的事情:如果我在(例如)中为“adjustment_negative”变量分配一个值,它会正确计算主屏幕上的退款总额,但如果我点击实际的贷项通知单并查看总额细分,调整费为 0.00,贷项通知单或主订单的信息视图上的总额没有更改(根据我的代码,总退款是错误的!)。$data array
$creditmemo = $service->prepareCreditmemo($data)
任何帮助将不胜感激!
$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());
}