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

添加Magento批量修改订单状态Completed选项

时间:2016-05-06 16:53来源: 作者: 点击:
Magento后台的订单状态比较难管理,系统没有直接更改订单状态为Completed,后台必须按照其规定:先发货(Shipped)再生成发票(Invoiced)之后才能将订单状态改为Completed,介绍用修改代码的方

Magento后台的订单状态比较难管理,系统没有直接更改订单状态为Completed,后台必须按照其规定:先发货(Shipped)再生成发票(Invoiced)之后才能将订单状态改为Completed,介绍用修改代码的方式实现批量更改订单状态为Completed 功能.

步骤如何:
1.先将网站代码备份一下,接下来修改以下三个文件:

app/code/core/Mage/Adminhtml/Block/Sales/Order/grild.php
app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
app/code/core/Mage/Sales/Model/Order.php

1. 在后台订单列表中Action增加Complete 下拉选项
打开文件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会报错,提示不允许手动修改订单的状态,我们还要做左后一步的修改.

取消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);

保存好,再去试试,是不是成功了。

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