dousonghs58612 2014-12-03 03:39
浏览 107
已采纳

**关闭**如何使用自定义表格像Sales-> Orders创建magento管理员自定义页面

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条回答 默认 最新

  • douqianzha6213 2014-12-03 05:13
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄