0

I have to create custom module, in this module have a grid, in this grid such as a some fields, like, order_id,product_name, etc in that field how to get order data?

here is my Grid.php Code

<?php

class Mt_Wizardsports_Block_Adminhtml_Wizardsports_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('wizardsportsGrid');
        // This is the primary key of the database
        $this->setDefaultSort('wizardsports_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('wizardsports/wizardsports')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('wizardsports_id', array(
            'header'    => Mage::helper('wizardsports')->__('ID'),
            'align'     =>'right',
            'width'     => '50px',
            'index'     => 'wizardsports_id',

        ));

        $this->addColumn('order_id', array(
            'header'    => Mage::helper('wizardsports')->__('Order ID'),
            'align'     =>'right',
            'width'     => '50px',
            'index'     => 'order_id',
        ));


        $this->addColumn('product_name', array(
            'header'    => Mage::helper('wizardsports')->__('Product Name'),
            'align'     =>'left',
            'index'     => 'product_name',
        ));

        $this->addColumn('find_wizardsports', array(
            'header'    => Mage::helper('wizardsports')->__('How To Find Wizardsports?'),
            'align'     =>'left',
            'index'     => 'find_wizardsports',
        ));



        return parent::_prepareColumns();
    }

    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }


}
1
  • i want to get sales order data in this custom field grid
    – R_Solanki
    Jun 19 '17 at 5:46
0

Change your _prepareCollection method to

protected function _prepareCollection()
{
   $collection = Mage::getModel('sales/order')->getCollection();
   $this->setCollection($collection);
   return parent::_prepareCollection();
}

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.