无法getParam()

时间:2012-07-06 05:45:21

标签: php magento

我想在Magento admin。

上添加Sales> Order的操作

Screenshot-
enter image description here

我遵循了此博客中的第二种方法 - 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?或者,如果它们已经设定,那么如何获得它们?

谢谢!

1 个答案:

答案 0 :(得分: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()));
}

希望有所帮助!