向Magento销售订单添加列后,网格排序和搜索无效

时间:2014-07-26 06:44:03

标签: magento magento-1.7

我已将装运方法的列添加到销售订单网格中。但是现在排序和搜索不适用于任何列。即使我从视图下拉菜单中选择20,我一次也会列出65个订单。

我为此创建了一个自定义模块,我在发货信息列下获得了正确的值。

以下是我在Grid.php文件中的代码。

<?php
  class Mynamespace_Ordergrid_Block_Adminhtml_Sales_Order_Grid  extends Mage_Adminhtml_Block_Sales_Order_Grid
    {      
        protected function _prepareCollection()
        {
            $collection = Mage::getResourceModel($this->_getCollectionClass());
            $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));
            $this->setCollection($collection);      
        }

        protected function _prepareColumns() {
             $this->addColumn('shipping_description', array(
                'header' => Mage::helper('sales')->__('Shipping Method'),
                'index' => 'shipping_description',
                'filter_index'=>'sales_flat_order.shipping_description',
             ));    
            return parent::_prepareColumns();  
        }   

        public function getGridUrl()
        {
            return $this->getUrl('*/*/grid', array('_current'=>true));
        }
    }
?>

Screenshot

请帮忙

1 个答案:

答案 0 :(得分:0)

muk,请尝试以下

      protected function _prepareCollection()
        {
            $collection = Mage::getResourceModel($this->_getCollectionClass());
  $collection->getSelect()->join(array('myorder'=>'sales_flat_order'),'main_table.entity_id=myorder.entity_id',array('myorder.shipping_method as  myorder_shipping_method'));

            $this->setCollection($collection);

            return parent::_prepareCollection();
        }

的列视图
   $this->addColumn('myorder_shipping_method', array(
        'header' => Mage::helper('sales')->__('Status'),
        'index' => 'myorder_shipping_method',
        'type'  => 'options',
        'width' => '70px',
        'options' => $this->toOptionArray(),
    ));

添加新功能

public function toOptionArray($isMultiSelect = false)
{
    $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();

    $options = array();

    foreach($methods as $_code => $_method)
    {
        if(!$_title = Mage::getStoreConfig("carriers/$_code/title"))
            $_title = $_code;
        $options[$_code.'_'.$_code] = $_title . " ($_code)";
    }
    return $options;
}