Magento后台的“Sales > Orders”和“Sales > Orders > Create New Order” 网格里没有“用户组”这一列。为什么我们需要这一列呢?也许你需要在网格中列出/筛选“经销商”组支付的订单。也许你能够筛选 “Sales > Orders > Create New Order” 网格通过在创建订单前的用户组来查看“经销商”客户数量。 默认情况下“Sales > Orders” 网格使用“sales_flat_order_grid”进行渲染。这个表基本上是“sales_flat_order”表的冗余子组。令人惊讶的是“sales_flat_order” 表里有“customer_group_id”列,而“sales_flat_order_grid”表中没有。所以我们第一步就是要添加“customer_group_id”列到“sales_flat_order_grid”表中。 我们通过一个类似这样的简单升级脚本来实现: $installer->getConnection() ->addColumn($installer->getTable('sales/order_grid'), 'customer_group_id', array( 'TYPE' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'NULLABLE' => false, 'DEFAULT' => '0', 'COMMENT' => 'Customer Group' )); 如果这个安装/升级脚本执行成功,我们就会在“sales_flat_order_grid”表中看到“customer_group_id”列。注意,Magento会在新订单保存时自动填充“sales_flat_order_grid.customer_group_id”中的数据。 然后我们将重写Mage_Adminhtml_Block_Sales_Order_Grid和Mage_Adminhtml_Block_Sales_Order_Create_Customer_Grid。但只做些小的修改来让我们的“Customer Group”显示。 我们通过config.xml来添加合适的入口: <global> <blocks> <adminhtml> <rewrite> <sales_order_create_customer_grid>Mycompany_Myextension_Block_Adminhtml_Sales_Order_Create_Customer_Grid</sales_order_create_customer_grid> <sales_order_grid>Mycompany_Myextension_Block_Adminhtml_Sales_Order_Grid</sales_order_grid> </rewrite> </adminhtml> </blocks> </global> 最后,添加重写模块 <?php class Mycompany_Myextension_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid { protected function _prepareColumns() { $groups = Mage::getResourceModel('customer/group_collection') ->addFieldToFilter('customer_group_id', array('gt'=> 0)) ->load() ->toOptionHash(); $this->addColumn('customer_group_id', array( 'header' => Mage::helper('customer')->__('Customer Group'), 'width' => '100', 'index' => 'customer_group_id', 'type' => 'options', 'options' => $groups, )); $this->addColumnsOrder('customer_group_id', 'shipping_name'); return parent::_prepareColumns(); } } <?php class Mycompany_Myextension_Block_Adminhtml_Sales_Order_Create_Customer_Grid extends Mage_Adminhtml_Block_Sales_Order_Create_Customer_Grid { protected function _prepareColumns() { $groups = Mage::getResourceModel('customer/group_collection') ->addFieldToFilter('customer_group_id', array('gt'=> 0)) ->load() ->toOptionHash(); $this->addColumn('group', array( 'header' => Mage::helper('customer')->__('Group'), 'width' => '100', 'index' => 'group_id', 'type' => 'options', 'options' => $groups, )); $this->addColumnsOrder('group', 'email'); return parent::_prepareColumns(); } }(责任编辑:最模板) |