0

Magento管理者の[販売]>[注文]にアクションを追加したいと思いました。

スクリーンショット-
ここに画像の説明を入力してください

私はこのブログの2番目の方法に従いました-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()));
    }
}

上記の2つの関数をからコピーし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 に答える