服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

修改Magento已存在的订单的运费

时间:2015-07-14 23:40来源:未知 作者:最模板 点击:
遇到一种magento情况,需要在下单后再由管理员添加订单运费,然后顾客再付款。那么问题来了,如何给订单添加运费呢?下面是一段代码,可以实现magento该功能: $orderId = your order id;
遇到一种magento情况,需要在下单后再由管理员添加订单运费,然后顾客再付款。那么问题来了,如何给订单添加运费呢?下面是一段代码,可以实现magento该功能:
$orderId = 'your order id';
$order = Mage::getModel('sales/order')->load($orderId);
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = $order->getOrderCurrencyCode();
$shippingAmount = Mage::helper('directory')->currencyConvert($params['shipping']['amount'], $currentCurrencyCode, $baseCurrencyCode);
$notify = isset($params['shipping']['is_customer_notified']) ? true : false;
 
 
 
$order->setBaseGrandTotal($order->getBaseGrandTotal() + $shippingAmount);
$order->settBaseSubtotal($order->getBaseSubtotal() + $shippingAmount);
//$order->setBaseSubtotalInvoiced($order->getBaseSubtotalInvoiced() + $shippingAmount);
//$order->setBaseTotalInvoiced($order->getBaseTotalInvoiced() + $shippingAmount);
//$order->setBaseTotalPaid($order->getBaseTotalPaid() + $shippingAmount);
$order->setGrandTotal($order->getGrandTotal() + $shippingAmount);
$order->setSubtotal($order->getSubtotal());
//$order->setSubtotalInvoiced($order->getSubtotalInvoiced() + $shippingAmount);
//$order->setTotalInvoiced($order->getTotalInvoiced() + $shippingAmount);
//$order->setTotalPaid($order->getTotalPaid() + $shippingAmount);
$order->setBaseSubtotalInclTax($order->getBaseSubtotalInclTax() + $shippingAmount);
$order->setSubtotalInclTax($order->getSubtotalInclTax() + $shippingAmount);
$order->setTotalDue($order->getTotalDue() - $order->getShippingAmount() + $shippingAmount);
$order->setShippingAmount($shippingAmount); $order->setBaseShippingAmount($shippingAmount); 
Mage::getModel('wholesale/core')->sendOrderEmail($order, 'wholesale_savers_order_update', $attch = '');
$order->setCarriageConfirmed(1); 
$order->save();

上述的代码中,关于Invoice的都是注释掉的,下面分两个情况说一下:

当订单还是pending的时候,如果上面的Invoice代码没有注释掉,那么当你在后台点击生成Invoice的时候,生成的invoice将不会包含你添加的运费的金额。例如订单的金额是1000,后台添加了20块运费,那么在生成invoice的时候,invoice的金额就是1000,不会是1020。只有在添加运费时不设置SubtotalInvoiced等才会是1020.


(责任编辑:最模板)
顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容