最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > Magento > Magento教程 >

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

时间:2014-05-27 00:54来源:未知 作者:最模板zuimoban 点击:
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);

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

(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容