2015-02-07 8 views
0

Magento 1.9.0.1을 사용하고 있습니다!Magento - Adminhtml 표에서 사용자 정의 MySQL 테이블에서 데이터를 가져 오는 방법

지금은 맞춤 magento 확장 작업을하고 있습니다. 사용자 정의 MySQL 테이블의 데이터를 HTML 그리드 테이블의 사용자 정의 페이지에 표시하려고합니다.

여기에 내가 작성한 모든 파일이 있습니다. 내/응용 프로그램/코드/사회/VivasIndustries/SmsNotification/차단/Adminhtml/판매/상태에서

<?xml version="1.0"?> 
<config> 
    <modules> 
    <VivasIndustries_SmsNotification> 
     <version>0.1.0</version> 
    </VivasIndustries_SmsNotification> 
    </modules> 
    <global> 
    <models> 
     <smsnotification> 
      <class>VivasIndustries_SmsNotification_Model</class> 
      <resourceModel>vivasindustries_smsnotification_resource</resourceModel> 
     </smsnotification> 
     <vivasindustries_smsnotification_resource> 
     <class>VivasIndustries_SmsNotification_Model_Resource</class> 
     <entities> 
      <smsnotification> 
      <table>VivasIndustries_SmsNotification</table> 
      </smsnotification> 
     </entities> 
     </vivasindustries_smsnotification_resource> 
    </models> 
    <resources> 
     <smsnotification_setup> 
      <setup> 
       <module>VivasIndustries_SmsNotification</module> 
      </setup> 
      <connection> 
       <use>core_setup</use> 
      </connection> 
     </smsnotification_setup> 
     <smsnotification_read> 
      <connection> 
       <use>core_read</use> 
      </connection> 
     </smsnotification_read> 
     <smsnotification_write> 
      <connection> 
       <use>core_write</use> 
      </connection> 
     </smsnotification_write> 
    </resources>  
    <events> 
     <sales_order_save_after> 
      <observers> 
       <vivasindustries_smsnotification> 
        <class>smsnotification/observer</class> 
        <method>orderSaved</method> 
       </vivasindustries_smsnotification> 
      </observers> 
     </sales_order_save_after> 
    </events> 
    <helpers> 
     <smsnotification> 
      <class>VivasIndustries_SmsNotification_Helper</class> 
     </smsnotification> 
    </helpers> 
    <blocks> 
     <smsnotification> 
      <class>VivasIndustries_SmsNotification_Block</class> 
     </smsnotification> 
    </blocks> 
    </global> 
    <adminhtml> 
    <acl> 
     <resources> 
      <all> 
       <title>Allow Everything</title> 
      </all> 
      <admin> 
       <children> 
        <system> 
         <children> 
          <config> 
           <children> 
            <vivas> 
             <title>Vivas - All</title> 
            </vivas> 
           </children> 
          </config> 
         </children> 
        </system> 
       </children> 
      </admin> 
     </resources> 
    </acl> 
    </adminhtml> 
    <admin> 
     <routers> 
      <adminhtml> 
       <args> 
        <modules> 
         <VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification> 
        </modules> 
       </args> 
      </adminhtml> 
     </routers> 
    </admin> 
</config>  

: 내 /app/code/community/VivasIndustries/SmsNotification/etc/config.xml에서

.PHP :

<?php 

class VivasIndustries_SmsNotification_Block_Adminhtml_Sales_Status_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->setId('smsnotification_grid'); 
     $this->setDefaultSort('increment_id'); 
     $this->setDefaultDir('DESC'); 
     $this->setSaveParametersInSession(true); 
     $this->setUseAjax(true); 
    } 

    protected function _prepareCollection() 
    { 
     $collection = Mage::getResourceModel('sales/order_collection') 
      ->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id AND a.address_type != \'billing\'', array(
       'city'  => 'city', 
       'country_id' => 'country_id' 
      )) 
      ->join(array('c' => 'customer/customer_group'), 'main_table.customer_group_id = c.customer_group_id', array(
       'customer_group_code' => 'customer_group_code' 
      )) 
      ->addExpressionFieldToSelect(
       'fullname', 
       'CONCAT({{customer_firstname}}, \' \', {{customer_lastname}})', 
       array('customer_firstname' => 'main_table.customer_firstname', 'customer_lastname' => 'main_table.customer_lastname')) 
      ->addExpressionFieldToSelect(
       'products', 
       '(SELECT GROUP_CONCAT(\' \', x.name) 
        FROM sales_flat_order_item x 
        WHERE {{entity_id}} = x.order_id 
         AND x.product_type != \'configurable\')', 
       array('entity_id' => 'main_table.entity_id') 
      ) 
     ; 

     $this->setCollection($collection); 
     parent::_prepareCollection(); 
     return $this; 
    } 

    protected function _prepareColumns() 
    { 
     $helper = Mage::helper('smsnotification'); 
     $currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE); 

     $this->addColumn('increment_id', array(
      'header' => $helper->__('Order #'), 
      'index' => 'increment_id' 
     )); 

     $this->addColumn('purchased_on', array(
      'header' => $helper->__('Purchased On'), 
      'type' => 'datetime', 
      'index' => 'created_at' 
     )); 

     $this->addColumn('products', array(
      'header'  => $helper->__('Products Purchased'), 
      'index'  => 'products', 
      'filter_index' => '(SELECT GROUP_CONCAT(\' \', x.name) FROM sales_flat_order_item x WHERE main_table.entity_id = x.order_id AND x.product_type != \'configurable\')' 
     )); 

     $this->addColumn('fullname', array(
      'header'  => $helper->__('Name'), 
      'index'  => 'fullname', 
      'filter_index' => 'CONCAT(customer_firstname, \' \', customer_lastname)' 
     )); 

     $this->addColumn('city', array(
      'header' => $helper->__('City'), 
      'index' => 'city' 
     )); 

     $this->addColumn('country', array(
      'header' => $helper->__('Country'), 
      'index' => 'country_id', 
      'renderer' => 'adminhtml/widget_grid_column_renderer_country' 
     )); 

     $this->addColumn('customer_group', array(
      'header' => $helper->__('Customer Group'), 
      'index' => 'customer_group_code' 
     )); 

     $this->addColumn('grand_total', array(
      'header'  => $helper->__('Grand Total'), 
      'index'   => 'grand_total', 
      'type'   => 'currency', 
      'currency_code' => $currency 
     )); 

     $this->addColumn('shipping_method', array(
      'header' => $helper->__('Shipping Method'), 
      'index' => 'shipping_description' 
     )); 

     $this->addColumn('order_status', array(
      'header' => $helper->__('Status'), 
      'index' => 'status', 
      'type' => 'options', 
      'options' => Mage::getSingleton('sales/order_config')->getStatuses(), 
     )); 

     $this->addExportType('*/*/exportInchooCsv', $helper->__('CSV')); 
     $this->addExportType('*/*/exportInchooExcel', $helper->__('Excel XML')); 

     return parent::_prepareColumns(); 
    } 

    public function getGridUrl() 
    { 
     return $this->getUrl('*/*/grid', array('_current'=>true)); 
    } 
} 
: 내 /app/code/community/VivasIndustries/SmsNotification/Block/Adminhtml/Sales/Status/Grid.php에서

<?php 

class VivasIndustries_SmsNotification_Block_Adminhtml_Sales_Status extends Mage_Adminhtml_Block_Widget_Grid_Container 
{ 
    public function __construct() 
    { 
     $this->_blockGroup = 'smsnotification'; 
     $this->_controller = 'adminhtml_sales_status'; 
     $this->_headerText = Mage::helper('smsnotification')->__('Send SMS on Order Status Changes'); 

     parent::__construct(); 
     $this->_removeButton('add'); 
    } 
} 

0

Grid.php 파일은 여기에서 가이드에서 가져온 것입니다 : http://inchoo.net/magento/how-to-create-a-custom-grid-from-scratch/이 대답에서 일부 편집 : https://magento.stackexchange.com/questions/54897/how-to-get-data-from-custom-mysql-table-into-your-adminhtml-grid-table/54898#54898

내가 당신에게 내가 그리드 테이블에 표시 할 구조와 데이터를 보여주지 :

을/응용 프로그램/코드/사회/VivasIndustries/SmsNotifi : https://magento.stackexchange.com/questions/54897/how-to-get-data-from-custom-mysql-table-into-your-adminhtml-grid-table/54898#54898 다음

난에있는 것입니다 : 내가 말을 들었다 때문에 대답 있도록 enter image description here

다음 3 개 개의 파일이 생성됩니다 양이온/모델/SmsNotification.php : 내 /app/code/community/VivasIndustries/SmsNotification/Model/Resource/Smsnotification.php에서

<?php 
class VivasIndustries_SmsNotification_Model_Smsnotification extends extends Mage_Core_Model_Abstract 
{ 
    public function _construct() 
    { 
     $this->_init('smsnotification/smsnotification'); 
    } 

} 

: 내/응용 프로그램/코드에서

<?php 
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification extends Mage_Core_Model_Resource_Db_Abstract 
{ 
    /** 
    * Initialize resource model 
    * 
    * @return void 
    */ 
    public function _construct() 
    { 
     $this->_init('smsnotification/smsnotification','id'); 
    } 
} 

/사회/VivasIndustries/SmsNotification/모델/자원/Smsnotification/Collection.php는 :

<?php 
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{ 
    protected function _constuct(){ 
     $this->_init('smsnotification/smsnotification');  
    } 
} 

내 문제는 내가 지금이 테이블은 데이터 F를 표시합니다 내 Grid.php 파일을 변경해야 할 것입니다 ROM 테이블 VivasIndustries_SmsNotification 전용?

미리 감사드립니다. 에서

+0

가 현재 표시되는 데이터를 테이블'VivasIndustries_SmsNotification'? – tsHunter

답변

0

당신의 /app/code/community/VivasIndustries/SmsNotification/Block/Adminhtml/Sales/Status/Grid.php _prepareCollection 기능 변경 : 그게 아닌

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