一、 后台订单列表grid页 1) 在订单grid列表中显示订单商品等,或联合查询其他表输出 奈何google又TM被封死了,百度能找到的方法,用起来不行。 因为我参照了 http://www.atwix.com/magento/adding-sku-column-to-orders-grid/(注:此文档已有两年多了,可以参考,硬搬会有几处错误), 几经修改将此功能写成了插件(Ludao_Adminrender), 试过简单暴力的方法,都不能翻页。
增加如支付方式、地址等, 由于join的数据表都是单列, 会简单一些。 而这里增加订单物品列(与显示物品缩略图类似), 用到 group_concat 。 网上的暴力方法,join了另外的数据表翻不了页,所以要重写block、 collection。 此方法需要新建一个插件模块,以下是我插件用的重要部分: <!-- app/code/local/Ludao/Adminrenderer/etc/config.xml 重写后台的 sales_order_grid(block)、 Order_Grid_Collection(resource) --> <global> ... <blocks> <adminhtml> <rewrite> <sales_order_grid>Ludao_Adminrenderer_Block_Adminhtml_Sales_Order_Grid</sales_order_grid> </rewrite> </adminhtml> </blocks> <models> ... <sales_resource> <rewrite> <order_grid_collection>Ludao_Adminrenderer_Model_Resource_Sales_Order_Grid_Collection</order_grid_collection> </rewrite> </sales_resource> ... </models> ... </global> 俺插件的block: app/code/local/Ludao/Adminrenderer/Block/Adminhtml/Sales/Order/Grid.php <?php class Ludao_Adminrenderer_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid { public function __construct() { parent::__construct(); $this->setId('sales_order_grid'); $this->setUseAjax(true); $this->setDefaultSort('created_at'); $this->setDefaultDir('DESC'); $this->setSaveParametersInSession(true); } /** * Retrieve collection class * * @return string */ protected function _getCollectionClass() { return 'sales/order_grid_collection'; } // 修改了这个方法 protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); // 增加 $itemTable = $collection->getTable('sales/order_item'); $collection->getSelect()->joinLeft( $itemTable, "{$itemTable}.order_id=`main_table`.entity_id", array('order_products' => new Zend_Db_Expr('group_concat('. $itemTable .'.name SEPARATOR "<br>")')) ) ->group('main_table.entity_id'); $this->setCollection($collection); return parent::_prepareCollection(); } // 修改此方法 protected function _prepareColumns() { $this->addColumn('real_order_id', array( 'header'=> Mage::helper('sales')->__('Order #'), 'width' => '80px', 'type' => 'text', 'index' => 'increment_id', )); if (!Mage::app()->isSingleStoreMode()) { $this->addColumn('store_id', array( 'header' => Mage::helper('sales')->__('Purchased From (Store)'), 'index' => 'store_id', 'type' => 'store', 'store_view'=> true, 'display_deleted' => true, )); } $this->addColumn('created_at', array( 'header' => Mage::helper('sales')->__('Purchased On'), 'index' => 'created_at', 'filter_index' => 'main_table.created_at', // 增加 main_table ,避免filter时出错 'type' => 'datetime', 'width' => '100px', )); $this->addColumn('billing_name', array( 'header' => Mage::helper('sales')->__('Bill to Name'), 'index' => 'billing_name', )); $this->addColumn('shipping_name', array( 'header' => Mage::helper('sales')->__('Ship to Name'), 'index' => 'shipping_name', )); // 增加列 $this->addColumn('order_products', array( 'header' => Mage::helper('sales')->__('Order Products'), 'index' => 'order_products', 'filter_index' => 'name', // 'filter_condition_callback' => array('Ludao_Adminrenderer_Model_Observer', 'filterItems'), 'type' => 'text', 'filter' => false, 'sortable' => false )); $this->addColumn('base_grand_total', array( 'header' => Mage::helper('sales')->__('G.T. (Base)'), 'index' => 'base_grand_total', 'type' => 'currency', 'currency' => 'base_currency_code', )); $this->addColumn('grand_total', array( 'header' => Mage::helper('sales')->__('G.T. (Purchased)'), 'index' => 'grand_total', 'type' => 'currency', 'currency' => 'order_currency_code', )); $this->addColumn('status', array( 'header' => Mage::helper('sales')->__('Status'), 'index' => 'status', 'type' => 'options', 'width' => '70px', 'options' => Mage::getSingleton('sales/order_config')->getStatuses(), )); if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { $this->addColumn('action', array( 'header' => Mage::helper('sales')->__('Action'), 'width' => '50px', 'type' => 'action', 'getter' => 'getId', 'actions' => array( array( 'caption' => Mage::helper('sales')->__('View'), 'url' => array('base'=>'*/sales_order/view'), 'field' => 'order_id' ) ), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'is_system' => true, )); } $this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS')); $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV')); $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML')); return parent::_prepareColumns(); } protected function _prepareMassaction() { $this->setMassactionIdField('entity_id'); $this->getMassactionBlock()->setFormFieldName('order_ids'); $this->getMassactionBlock()->setUseSelectAll(false); if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) { $this->getMassactionBlock()->addItem('cancel_order', array( 'label'=> Mage::helper('sales')->__('Cancel'), 'url' => $this->getUrl('*/sales_order/massCancel'), )); } if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) { $this->getMassactionBlock()->addItem('hold_order', array( 'label'=> Mage::helper('sales')->__('Hold'), 'url' => $this->getUrl('*/sales_order/massHold'), )); } if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) { $this->getMassactionBlock()->addItem('unhold_order', array( 'label'=> Mage::helper('sales')->__('Unhold'), 'url' => $this->getUrl('*/sales_order/massUnhold'), )); } $this->getMassactionBlock()->addItem('pdfinvoices_order', array( 'label'=> Mage::helper('sales')->__('Print Invoices'), 'url' => $this->getUrl('*/sales_order/pdfinvoices'), )); $this->getMassactionBlock()->addItem('pdfshipments_order', array( 'label'=> Mage::helper('sales')->__('Print Packingslips'), 'url' => $this->getUrl('*/sales_order/pdfshipments'), )); $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array( 'label'=> Mage::helper('sales')->__('Print Credit Memos'), 'url' => $this->getUrl('*/sales_order/pdfcreditmemos'), )); $this->getMassactionBlock()->addItem('pdfdocs_order', array( 'label'=> Mage::helper('sales')->__('Print All'), 'url' => $this->getUrl('*/sales_order/pdfdocs'), )); $this->getMassactionBlock()->addItem('print_shipping_label', array( 'label'=> Mage::helper('sales')->__('Print Shipping Labels'), 'url' => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'), )); return $this; } public function getRowUrl($row) { if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId())); } return false; } public function getGridUrl() { return $this->getUrl('*/*/grid', array('_current'=>true)); } }
俺插件的collection : app/code/local/Ludao/Adminrenderer/Model/Resource/Sales/Order/Grid/Collection.php , 重写 getSelectCountSql() <?php class Ludao_Adminrenderer_Model_Resource_Sales_Order_Grid_Collection extends Mage_Sales_Model_Resource_Order_Grid_Collection{ /** * Get SQL for get record count * @return Varien_Db_Select */ public function getSelectCountSql() { $countSelect = parent::getSelectCountSql(); if (Mage::app()->getRequest()->getControllerName() == 'sales_order') { $countSelect->reset(Zend_Db_Select::GROUP); $countSelect->reset(Zend_Db_Select::COLUMNS); $countSelect->columns("COUNT(DISTINCT main_table.entity_id)"); } return $countSelect; } } 简单来讲,就是重置掉 查询计数的Sql 的 group_concat 字段。 详情还是参见前面的链接。
二、 后台订单View页 1) 加入图片预览。 修改 app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml, 在 <?php if ($this->canDisplayContainer()): ?> 之前插入: <div style="width:60px;height:60px;float:left;display:inline-block;"> <?php $_product = Mage::getModel('catalog/product')->load($_item->getProductId());?> <a target="_blank" href="<?php echo $_product->getImageUrl(); ?>"> <img height="60" width="60" src="<?php echo $_product->getThumbnailUrl(); ?>"> </a> </div>
(测试 magento版本 1.8.0 ) (责任编辑:最模板) |