Saya telah melakukan hal yang sama. Menambahkan bidang 'order_type' secara berurutan dan ditampilkan dalam kisi. Ini berfungsi dengan baik di Magento ver 1.7.0.2
Bagaimana cara menambahkan bidang Jenis Pesanan dalam kisi pesanan penjualan di admin?
1) Kita harus membuat satu instal file sql dengan kode di bawah ini.
<?php
/* @var $installer Mage_Sales_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();
$installer->run("
ALTER TABLE `{$installer->getTable('sales/order')}` ADD `order_type` VARCHAR(255) NOT NULL;
ALTER TABLE `{$installer->getTable('sales/order_grid')}` ADD `order_type` VARCHAR(255) NOT NULL;
ALTER TABLE `{$installer->getTable('sales/quote')}` ADD `order_type` VARCHAR(255) NOT NULL;
");
$installer->endSetup();
?>
2) Ganti file Mage_Adminhtml_Block_Sales_Order_Grid dan tambahkan kode di bawah ini di dalamnya.
<?php
class Mycompany_Mymodule_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareColumns()
{
$options = array(
'ordertypeID1' => 'order type label1',
'ordertypeID2' => 'order type label2',
'ordertypeID3' => 'order type label3',
);
$this->addColumn('order_type', array(
'header' => Mage::helper('customer')->__('Order Type'),
'width' => '100',
'index' => 'order_type',
'type' => 'options',
'options' => $options
));
$this->addColumnsOrder('order_type', 'grand_total');
return parent::_prepareColumns();
}
}
?>
3) Buat satu peristiwa pengamat untuk menambah / memperbarui nilai bidang jenis pesanan
Buka modul Anda / etc / config.xml
<config>
<adminhtml>
<events>
<adminhtml_sales_order_create_process_data>
<observers>
<modulename>
<class>Mycompany_Mymodule_Model_Adminhtml_Observer</class>
<method>adminhtml_sales_order_create_process_data</method>
</modulename>
</observers>
</adminhtml_sales_order_create_process_data>
<sales_convert_quote_to_order>
<observers>
<modulename>
<type>model</type>
<class>Mycompany_Mymodule_Model_Adminhtml_Observer</class>
<method>sales_convert_quote_to_order</method>
</modulename>
</observers>
</sales_convert_quote_to_order>
</events>
</adminhtml>
</config>
4) Buat satu file pengamat kelas Mycompany_Mymodule_Model_Adminhtml_Observer
<?php
class Mycompany_Mymodule_Model_Adminhtml_Observer
{
public function adminhtml_sales_order_create_process_data(Varien_Event_Observer $observer)
{
try {
$requestData = $observer->getEvent()->getRequest();
if (isset($requestData['order']['order_type'])) {
$observer->getEvent()->getOrderCreateModel()->getQuote()
->addData($requestData['order'])
->save();
}
} catch (Exception $e) {
Mage::logException($e);
}
return $this;
}
/**
*
* @param Varien_Event_Observer $observer
* @return Mycompany_Mymodule_Model_Adminhtml_Observer
*/
public function sales_convert_quote_to_order(Varien_Event_Observer $observer)
{
if ($ordertype = $observer->getEvent()->getQuote()->getOrderType()) {
try {
$observer->getEvent()->getOrder()
->setOrderType($ordertype);
} catch (Exception $e) {
Mage::logException($e);
}
}
return $this;
}
}
?>