zoukankan      html  css  js  c++  java
  • Magento 批量修改订单状态为 Completed

    Magento的订单状态比较难控制,系统不允许用户手动更改订单的状态,必须按照其规定,先发货(Shipped)再生成发票(Invoiced)之后才能将订单状态改为Completed,本文介绍用修改代码的方式实现批量更改订单状态为Completed 功能.
    首先,将自己的网站代码备份好,需要修改的文件由以下三个:
    /public_html/app/code/core/Mage/Adminhtml/Block/Sales/Order/grild.php
    /public_html/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
    /public_html/app/code/core/Mage/Sales/Model/Order.php
     
    1. 在后台订单列表中Action增加Complete 按钮
    打开下列文件/public_html/app/code/core/Mage/Adminhtml/Block/Sales/Order/grild.php
    protected function _prepareMassaction()中 $this->getMassactionBlock()->setUseSelectAll(false);增加 
    $this->getMassactionBlock()->addItem('complete_order', array( 'label'=> Mage::helper('sales')->__('Complete'),'url' => $this->getUrl('* 
    public function massCompleteAction() 
    $orderIds = $this->getRequest()->getPost('order_ids', array()); 
    $countCompleteOrder = 0; 
    foreach ($orderIds as $orderId) { 
    $order = Mage::getModel('sales/order')->load($orderId); 
    if ($order->canComplete()) { 
    $order->complete() 
    ->save(); 
    $countCompleteOrder++; 
    if ($countCompleteOrder>0) { 
    $this->_getSession()->addSuccess($this->__('%s order(s) successfully put on complete', $countCompleteOrder)); 
    else { 
    // selected orders is not available for hold 
    $this->_redirect('* 
    public function canComplete() 
    if ($this->getState() === self::STATE_CANCELED || 
     
    $this->getState() === self::STATE_CLOSED 
    ) { 
    return false; 
    }
     
    if ($this->getActionFlag(self::ACTION_FLAG_COMPLETE) === false) { 
    return false; 
    }
     
    return true; 
    }
     
    public function complete() 
    if (!$this->canComplete()) { 
    Mage::throwException(Mage::helper('sales')->__('Complete action is not available')); 
    $this->setHoldBeforeState($this->getState()); 
    $this->setHoldBeforeStatus($this->getStatus()); 
    $this->setState(self::STATE_COMPLETE, true); 
    return $this; 
    }
     
    这样,批量修改订单状态为Completed功能就实现了,如果这时尝试修改订单状态的话,Magento会报错,提示不允许手动修改订单的状态,我们还要做左后一步的修改
     
    4. 取消Magento限制手动修改订单状态的限制
    还是在/public_html/app/code/core/Mage/Sales/Model/Order.php,找到这句代码
    return $this->_setState($state, $status, $comment, $isCustomerNotified, true);改为
    return $this->_setState($state, $status, $comment, $isCustomerNotified, false);
    这样,我们就实现了批量修改订单状态为Completed功能。
     
    实现批量修改订单状态的功能后,下面就是如何使用这个功能批量修改订单的状态为Completed,并利用Magento系统给客户发邮件提示订单状态已经改变。

    1.登录进入后台,进入 Sales - Orders
     
    2.在此列表中,选择要修改状态的订单,然后在右上角的 Action 下拉表中选择 Complete
    Magento <wbr>批量修改订单状态为 <wbr>Completed <wbr>之二

    3.点击Submit,订单状态就应该修改为Completed了
     
    4.点击某一个状态为Completed的订单,进入订单详细页面(注意!订单状态一定要是Complete才能给客户发提醒邮件)
     
    5.在订单详细页的底部,找到Comments History,将客户订单的发货日期,追踪号填上即可,如图所示,注意要勾选Notify Customer by Email 和 Visible on Front-end
    Magento <wbr>批量修改订单状态为 <wbr>Completed <wbr>之二
     
    6. 然后点击Submit Comment 系统就会发送一封邮件给客户提示订单状态的改变,如下图

    Magento <wbr>批量修改订单状态为 <wbr>Completed <wbr>之二
  • 相关阅读:
    生成15位或者4位随机数 (主要用于微信支付订单号)
    支付签名 MD5Util 排序工具类
    JVM垃圾回收(GC)
    JVM内存区域
    Java实现经典七大经典排序算法
    Java设计模式之装饰者模式
    Java设计模式之单例模式
    提前批笔试一道算法题的Java实现
    Java设计模式之工厂模式
    文件上传和下载
  • 原文地址:https://www.cnblogs.com/jevil/p/2984773.html
Copyright © 2011-2022 走看看