**closed** How to create magento admin custom page with custom table Like Sales->Orders

1.4k views Asked by At

CLosed I can do it I mix code from 2 answer to make my page

I want to make special order page with My custom database table

Can I create New magento admin Page layout like this

I want layout like this page

I want to show

Orders OrdersDate CustomerID CustomerCompany SKU ProductName Qty, Total Status Action

and mydatabase table name is specialorder in Fields in table have

order_no PK (from product id)
order_item_number PK (to show in Orders)
creat_date (to show in OrdersDate)
Cusid (to show in CustomerID)
Cusname (to show in CustomerCompany)
sku (to show in SKU)
Productname (to show in ProductName )
price 
qty (to show in Qty,)
total_price (to show in Total)
status (to show in Status)

data in table like this (order_no + order_item_no = pk)

1 1 date cusid cusname sku P.name price qty total status

2 1 date cusid cusname sku P.name price qty total status

2 2 date cusid cusname sku P.name price qty total status

How can I use this table to show in my custom admin page

2

There are 2 answers

17
Deepak Mankotia On BEST ANSWER

Follow the following steps to create module in admin panel with your custom table.

Create module in your local directory (app/code/local/Pfay/Test), Where test -> . Inside this structure create all these directories Helper,etc,Block,Model,Controllers

Lets start with etc create config.xml file in side this :

<?xml version="1.0"?>
  <config>
    <modules>
        <Pfay_Test>
          <version>1.0.0</version>
        </Pfay_Test>
    </modules>
    <global>
            <blocks>
                <test>
                     <class>Pfay_Test_Block</class>
                </test>
            </blocks>
            <models>
                <test>
                     <class>Pfay_Test_Model</class>
                     <resourceModel>test_mysql4</resourceModel>
                 </test>
                <test_mysql4>
                     <class>Pfay_Test_Model_Mysql4</class>
                     <entities>
                         <test>
                           <table>pfay_test</table>
                         </test>
                      </entities>
                </test_mysql4>
            </models>
                <!-- allow the plugin to read and write -->
            <resources>
                    <!-- connection to write -->
                    <test_write>
                        <connection>
                            <use>core_write</use>
                        </connection>
                    </test_write>
                    <!-- connection to read -->
                   <test_read>
                      <connection>
                         <use>core_read</use>
                      </connection>
                   </test_read>
            </resources>
             <!-- -/- -->
    </global>
     <frontend>
       <routers>
          <routeurfrontend>
              <use>standard</use>
              <args>
                 <module>Pfay_Test</module>
                 <frontName>test</frontName>
              </args>
          </routeurfrontend>
       </routers>
       <layout>
           <updates>
                <test>
                     <file>test.xml</file>
                </test>
            </updates>
        </layout>
    </frontend>
        <admin>
         <routers>
             <test>
                <use>admin</use>
                <args>
                   <module>Pfay_Test</module>
                   <frontName>admintest</frontName>
                </args>
             </test>
          </routers>
     </admin>
     <adminhtml>
       <layout>
          <updates>
              <test>
                  <file>test.xml</file>
               </test>
          </updates>
       </layout>
       <menu>
          <test translate="title" module="adminhtml">
             <title>Import XLS</title>
             <sort_order>100</sort_order>
             <children>
                 <set_time>
                       <title>Add product through XLS</title>
                       <action>admintest/adminhtml_index</action>
                  </set_time>
              </children>
           </test>
        </menu>
    </adminhtml>
</config>

My table name is Pfay_test add your table name instead of this.

Now in controllers create directory Adminhtml inside this create create your controller IndexController.php

<?php
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
    protected function _initAction()
    {
        $this->loadLayout()->_setActiveMenu('test/set_time')
                ->_addBreadcrumb('test Manager','test Manager');
       return $this;
     }
      public function indexAction()
      {
         $this->_initAction();
         $this->renderLayout();
      }

}

where set_time is you menu name added in config.xml file.

Now move to you block section where you will create you Grid. Inside Block directory create Adminhtml > Grid.php

class Pfay_Test_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
     //where is the controller
     $this->_controller = 'adminhtml_test';
     $this->_blockGroup = 'test';
     //text in the admin header
     $this->_headerText = 'XLS file management';
     //value of the add button

     parent::__construct();
     }
}

Next create a directory Test > Grid.php

<?php
class Pfay_Test_Block_Adminhtml_Test_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
   public function __construct()
   {
       parent::__construct();
       $this->setId('contactGrid');
       $this->setDefaultSort('id_pfay_test');
       $this->setDefaultDir('DESC');
       $this->setSaveParametersInSession(true);
   }
   protected function _prepareCollection()
   {
      $collection = Mage::getModel('test/test')->getCollection();
      $this->setCollection($collection);
      return parent::_prepareCollection();
    }
   protected function _prepareColumns()
   {
       $this->addColumn('id_pfay_test',
             array(
                    'header' => 'ID',
                    'align' =>'right',
                    'width' => '50px',
                    'index' => 'id_pfay_test',
               ));
       $this->addColumn('nom',
               array(
                    'header' => 'nom',
                    'align' =>'left',
                    'index' => 'nom',
              ));
       $this->addColumn('prenom', array(
                    'header' => 'prenom',
                    'align' =>'left',
                    'index' => 'prenom',
             ));
        $this->addColumn('telephone', array(
                     'header' => 'telephone',
                     'align' =>'left',
                     'index' => 'telephone',
          ));
         return parent::_prepareColumns();
    }
    public function getRowUrl($row)
    {
         return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
}

Now move to your Model Inside Model create Test.php and Mysql4

In Test.php :

<?php
class Pfay_Test_Model_Test extends Mage_Core_Model_Abstract
{
     public function _construct()
     {
         parent::_construct();
         $this->_init('test/test');
     }
}

Here (test/test) is Pfay_<modulename>_Model_<modulename> -> (<modulename>/<modulename>)

Now inside Pfay > Test > Model > Mysql4 folder create Test.php and Test

In Test.php :

<?php
class Pfay_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract
{
     public function _construct()
     {
         $this->_init('test/test', 'id_pfay_test');
     }
}

Where id_pfay_test is unique key of your table.

Pfay >Test >Model >Mysql4 >Test > create a file Collection.php

<?php
class Pfay_Test_Model_Mysql4_Test_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
 {
     public function _construct()
     {
         parent::_construct();
         $this->_init('test/test');
     }
}

Final step inform magento about your module : create file Pfay_Test.xml in

/app/etc/modules

<?xml version="1.0"?>
<config>
    <modules>
        <Pfay_Test>
            <active>true</active>
            <codePool>local</codePool>
        </Pfay_Test>
   </modules>

</config>

Note : Change Module name and package name according to you.

Feel free if you have any query regarding this.

3
Mikel Bitson On

Try using the built in Magento Grid. As to not duplicate content, try this: