0

我想在 Magento 管理员的销售>订单上添加一个操作。

截屏-
在此处输入图像描述

我遵循了这个博客中的第二种方法 - www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/

我的问题 - 我无法在操作控制器中获取订单 ID(用于对其执行操作)。
我的代码在class MyPackage_MyModule_IndexController extends Mage_Adminhtml_Controller_Action

protected function _initOrder()
{
    $id = $this->getRequest()->getParam('order_id'); ///TROUBLE HERE
    $order = Mage::getModel('sales/order')->load($id);

    if (!$order->getId()) {
        $this->_getSession()->addError($this->__('This order no longer exists.'));
        $this->_redirect('dash/sales_order');
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return false;
    }
    Mage::register('sales_order', $order);
    Mage::register('current_order', $order);
    return $order;
}
public function approvecodAction() {
    if ($order = $this->_initOrder()) {
        try {
            $order->setStatus('codapproved')
                ->save();
            $this->_getSession()->addSuccess(
                $this->__('The order has been approved for COD.')
            );
        }catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        }catch (Exception $e) {
            $this->_getSession()->addError($this->__('The order has not been approved for COD.'));
            Mage::logException($e);
        }
        $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
    }
}

注意我复制了上述两个函数app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php并为我的目的进行了修改。

请告诉我如何以及在哪里设置参数订单ID?或者如果他们正在设置,那么如何获得它们?

谢谢!

4

1 回答 1

1

您正在处理控制器上的批量操作回调,因此您将在参数中获得一组值,而不是单个值。您将需要在您的操作方法中执行更多类似的操作:

public function approvecodAction() {
    $orderIds = $this->getRequest()->getPost('order_ids', array());
    foreach ($orderIds as $orderId) {
        $order = Mage::getModel('sales/order')->load($orderId);

        try {
            $order->setStatus('codapproved')
            ->save();
            $this->_getSession()->addSuccess(
                    $this->__('The order has been approved for COD.')
            );
        }catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        }catch (Exception $e) {
            $this->_getSession()->addError($this->__('The order has not been approved for COD.'));
            Mage::logException($e);
        }
    }
    $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
}

希望有帮助!

于 2012-07-06T05:58:14.127 回答