我想导出“管理客户”网格,并且还想在网格末尾添加客户的IP地址 .
这是加载网格时执行的代码
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
$this->setCollection($collection);
return parent::_prepareCollection();
}
我还添加了一个专栏
$this->addColumn('ip_address', array(
'header' => Mage::helper('customer')->__('IP Address'),
'default' => Mage::helper('customer')->__('n/a'),
'index' => 'remote_addr',
'renderer' => 'adminhtml/customer_online_grid_renderer_ip',
'filter' => false,
'sort' => false
));
但我没有得到任何数据 .
如何在添加的列中获取客户IP地址
1 回答
To add ip addresses of the customers at the end of the grid :-
我们要创建一个自定义模块: -
我将名字命名为Wakar&Modulename作为Customeripaddress: -
1- app/etc/modules/Wakar_Customeripaddress.xml
首先,我们要 register 这个模块: -
2- app/code/local/Wakar/Customeripaddress/etc/config.xml :-
在这个文件中,我们定义了模块配置(块覆盖,控制器覆盖等) .
3-app/code/local/Wakar/Customeripaddress/sql/customerattribute1523689716_setup/mysql4-install-0.1.0.php
现在我们将创建一个客户自定义列,在客户注册期间,我们将使用此列保存访问者IP地址,稍后我们将获取此IP地址以通过渲染器显示客户IP地址 .
4- app/code/local/Wakar/Customeripaddress/controllers/Customer/AccountController.php :-
注册时保存客户IP地址: -
5- app/code/local/Wakar/Customeripaddress/Block/Adminhtml/Customer/Grid.php :-
在客户网格中添加IP地址: -
6- app/code/local/Wakar/Customeripaddress/Block/Adminhtml/Renderer/Location.php
使用渲染器在客户网格中显示IP地址: -
希望这能解决你的问题...... !!!