zoukankan      html  css  js  c++  java
  • 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.

    权当备忘。

  • 相关阅读:
    用js内置对象XMLHttpRequest 来用ajax
    HTTP 状态代码及其定义
    Delphi 字符类转换集《转》
    delphi 只允许运行一个实例的三种方法《转》
    时间加减函数(年、月、日)《转》
    删除数据库的表中某字段的值《转》
    Delphi 对话框《转》
    Delphi 给frxReport赋值《lcemeaning》
    点击链接弹出框提示《转》
    CentOS7上elasticsearch5.5启动报错
  • 原文地址:https://www.cnblogs.com/mityaya/p/4630777.html
Copyright © 2011-2022 走看看