2012-07-06 94 views
0

我想在Magento admin的Sales> Order中添加一個操作。無法獲取參數()

Screenshot-
enter image description here

我跟着從這個blog- www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/

第二種方法我problem- 我在我不能夠得到訂單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

您正在處理控制器上的批量操作回調,因此您將在參數中獲取一組值,而不是單個值。你需要在你的動作方法中做更多這樣的事情:

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())); 
} 

希望幫助!

+0

非常感謝!像魔術一樣工作。 :) – 2012-07-06 06:13:06

+0

哇,我印象深刻,我完全沒有測試那個笑。 – 2012-07-06 06:44:34