php - **关闭** 如何使用自定义表创建 magento 管理自定义页面,如销售-> 订单

标签 php mysql magento admin custom-pages

CLosed 我可以做到 我混合 2 个答案的代码来制作我的页面

我想用我的自定义数据库表制作特殊订单页面

我可以像这样创建新的 magento 管理页面布局吗

I want layout like this page

我要展示

Orders OrdersDate CustomerID CustomerCompany SKU ProductName Qty, Total Status Action

我的数据库表名是specialorder 在表中的字段有

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)

表格中的数据是这样的(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

我如何使用此表显示在我的自定义管理页面中

最佳答案

按照以下步骤使用您的自定义表格在管理面板中创建模块。

在本地目录 (app/code/local/Pfay/Test) 中创建模块,其中 test -> . 在这个结构中创建所有这些目录 Helper,etc,Block,Model,Controllers

让我们从 etc 开始,在这边创建 config.xml 文件:

<?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>

我的表名称是 Pfay_test 添加您的表名称而不是这个。

现在在 Controller 中创建目录 Adminhtml 在此创建创建您的 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();
      }

set_time 是您在 config.xml 文件中添加的菜单名称。

现在转到 block 部分,您将在其中创建网格。 在 Block 目录中创建 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();
     }
}

接下来创建目录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()));
    }
}

现在转到您的模型内部模型创建 Test.phpMysql4

在 Test.php 中:

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

这里(测试/测试)是Pfay_<modulename>_Model_<modulename> -> (<modulename>/<modulename>)

现在里面Pfay > Test > Model > Mysql4文件夹创建Test.php和测试

在 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');
     }
}

id_pfay_test 是您表的唯一键。

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

最后一步通知 magento 您的模块:在

中创建文件 Pfay_Test.xml

/app/etc/modules

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

</config>

注意:根据您更改模块名称和包名称。

如果您对此有任何疑问,请随时联系我们。

关于php - **关闭** 如何使用自定义表创建 magento 管理自定义页面,如销售-> 订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27263216/

相关文章:

php - WordPress get_query_var()

php - 如何通过作者用户名获取 Wordpress 文件?

php - 显示采集的、通过的、失败的和释放的血液成分的计数

MySQL 拒绝在 Ubuntu 中使用 Django

javascript - Magento 产品页面 - 显示缺货的相关产品

php - 简单的 Where 子句有语法错误

php - 使用 Laravel 干预图像缓存 : works once, 然后 "Image cannot be displayed as it contains errors"

php - 在类包装器中缓存 PDO 准备语句

php - Magento:在后端代码中以编程方式创建订单

php - 如何按键刷新Magento缓存?