1

I have override Grid.php of Order Grid, I want to add popup to link another module. I need to pass order ID to controller using url of popup link. please check below code

class Mycompany_Module_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    public $url;

     protected function _prepareColumns()
    {
        $test=Mage::getModel('sales/order')->getCollection();
            $array = array();
            foreach ($test as $_index=>$_item){
            $array[] = $_item->getId();
            }
            $OrderId=array_reverse($array);
            foreach($OrderId as $key=>$OrderIdValue){
            $this->url= $this->getUrl('*/module/index/', array('order_id' => $OrderIdValue)); // url generated correctly here
            $this->addColumn('upload',
                array(
                    'header'    => Mage::helper('core')->__('Pop up'),
                    'width'     => '50px',
                    'type'      => 'action',
                    'getter'     => 'getId',
                    'actions'   => array(
                        array(
                            'caption' => Mage::helper('sales')->__('Pop up'),
                            'onclick' =>"return myPop('".$this->url."')"   // generates only one url like /module/index/order_id/1
                        )
                    ),
                    'filter'    => false,
                    'sortable'  => false,
                    'index'     => 'stores',
                    'is_system' => true,
            ));


    } // for each ends here 

 return parent::_prepareColumns();
    }



}

I'm not able to iterate order_id here 'onclick' =>"return myPop('".$this->url."')"

  • For me the code works and the url is built as follows. admin/module/index/order_id/1/key/da0ea4f3d15a07e8eda8705612086eb8/ what is the url that is displayed for you? – David Manners Apr 29 '14 at 10:33
  • @David only this url generated, for order id 7 it must show admin/module/index/order_id/7/key/da0ea4f3d15a07e8eda8705612086eb8/ instead of admin/module/index/order_id/1/key/da0ea4f3d15a07e8eda8705612086eb8/ – Aniruddha A Deshpande Apr 29 '14 at 10:39
  • Ah no i see the issue. – David Manners Apr 29 '14 at 11:06
2

Solution was very each , use of sales- order model $test=Mage::getModel('sales/order')->getCollection(); was waste of time. I used 'popup' => true this syntax to get pop up window. I knew this syntax , but i thought it renders only Grid Url not other custom link.

array(
                    'header'    => Mage::helper('core')->__('Pop up'),
                    'width'     => '50px',
                    'type'      => 'action',
                    'getter'     => 'getId',
                    'actions'   => array(
                        array(
                            'caption' => Mage::helper('sales')->__('Pop up'),
                            'url'     => array('base'=>'*/module/index'),
                            'field'   => 'order_id',
                    'popup'   => true
                        )
                    ),
0

The problem is that each column in the _prepareColumns is processed on a row basis any way so what happens with your loop is it will add a column for each order but since the name is not unique then they will override each other and the last one will be taken. Hence why you are seeing only the final url. You do not need to loop through the orders yourself as Magento will do this when building the gird, I think as part of the _prepareColumns.

For a normal url the following will work.

protected function _prepareColumns()
{
    $this->addColumn('upload',
        array(
            'header'    => Mage::helper('core')->__('Pop up'),
            'width'     => '50px',
            'type'      => 'action',
            'getter'     => 'getId',
            'actions'   => array(
                array(
                    'caption' => Mage::helper('sales')->__('Pop up'),
                    'url'     => array('base'=>'*/module/index'),
                    'field'   => 'order_id'
                )
            ),
            'filter'    => false,
            'sortable'  => false,
            'index'     => 'stores',
            'is_system' => true,
        ));

    return parent::_prepareColumns();
}

This will add the order id from each row to build the correct url. Currently I am not sure how to add an onClick with this information.

  • method used here magento.stackexchange.com/questions/4449/…. and used by me is almost same but they have successfully rendered url – Aniruddha A Deshpande Apr 29 '14 at 12:14
  • @Aad yes that is the same as the code I have given you, this will work for a normal link but not for an onClick option. – David Manners Apr 29 '14 at 12:16
  • sorry i haven't mentioned in above comment even if you use url=>$this->url you will get same url – Aniruddha A Deshpande Apr 29 '14 at 12:20
  • @Aad yes you do not need the $this->url or the foreach as the grid will add the information as part of the prepareCollection call. If you remove the looping and update your code to match my answer then at least the link itself will be generated correctly. – David Manners Apr 29 '14 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.