Magento - 如何在订单网格过滤器中添加国家列?

标签 magento

我试过:

$collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->oinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
        $this->setCollection($collection);
        return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();

但结果是空白。 请帮助我在订单网格中添加国家列。谢谢。

最佳答案

复制到 app/code/core/Mage/Adminhtml/Block/Sales/Order/Gridapp/code/local/Mage/Adminhtml/Block/Sales/Order/Grid

在文件中添加以下代码,用于将账单地址附加到订单网格以用于 prepareCollection 函数

$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type =  'billing'");

完整代码为

  protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());


$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type =  'billing'");

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

然后将下面的代码添加到_prepareColumns()

 $this->addColumn('country_id', array(
            'header' => Mage::helper('sales')->__('Country Id'),
            'index' => 'country_id',
            'filter_index' => 'sales_flat_order_address.country_id',
        ));

如果想要国家列表然后添加下面的代码 _prepareCollection()

 $this->addColumn('country_id', array(
            'header' => Mage::helper('sales')->__('Country Id'),
            'index' => 'country_id',
        'type'=> 'options',
        'options'=>$this->getAllCountry(),      
            'filter_index' => 'sales_flat_order_address.country_id',
        ));

然后在这个文件上添加新的函数

public function getAllCountry(){
    $options = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray(); 
        $countries = array(); 
        foreach($options as $options){
             $countries[$options['value']]=$options['label']; 
            } 
    return $countries;
    }

有关 http://bluehorse.in/blog/how-to-add-some-field-or-column--into-magento-order-grid-in-magento-or-customized-magento-order-grid.html 的更多详细信息

http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/

关于Magento - 如何在订单网格过滤器中添加国家列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24421355/

相关文章:

magento - Magento:获取角色和用户

linux - 如何为 Docker 容器提供更多资源

magento - 如何在 Magento 中检索成功消息?

Magento:索引管理页面仅显示空白

Magento 中的 jQuery

magento - line1389 上的 fatal error :Call to a member function getSource()on a non-object in\app\cose\core\Mage\Catalog\Model\Product. php

Magento 获取给定页面的布局

php - 更新本地 MYSQL 版本 OSX

mysql - Magento:备份建议

magento - 类别描述不变