Magento--修改已存在的订单的运费
生活随笔
收集整理的這篇文章主要介紹了
Magento--修改已存在的订单的运费
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
遇到一種情況,需要在下單后再由管理員添加訂單運費,然后顧客再付款。那么問題來了,如何給訂單添加運費呢?下面是一段代碼,可以實現(xiàn)該功能:
$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.
?
權(quán)當備忘。
?
轉(zhuǎn)載于:https://www.cnblogs.com/mityaya/p/4630777.html
總結(jié)
以上是生活随笔為你收集整理的Magento--修改已存在的订单的运费的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sscanf的高级用法
- 下一篇: 周进度总结表(一)