I have seen There is grid in magento admin for see online customer on store at Customer->Online Customers
Now I want to add location here in grid. Is it possible to add location ? If Yes. How to add? I can see ip of customer here.
I have seen There is grid in magento admin for see online customer on store at Customer->Online Customers
Now I want to add location here in grid. Is it possible to add location ? If Yes. How to add? I can see ip of customer here.
Copy file /app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php
to /app/code/local/Mage/Adminhtml/Block/Customer/Online/Grid.php
Add following code in _prepareColumns
function before return
statement.
$this->addColumn('location', array(
'header' => Mage::helper('customer')->__('Location'),
'default' => Mage::helper('customer')->__('n/a'),
'index' => 'remote_addr',
'renderer' => 'adminhtml/customer_online_grid_renderer_location',
'filter' => false,
'sort' => false
));
Create file /app/code/local/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Location.php
<?php
class Mage_Adminhtml_Block_Customer_Online_Grid_Renderer_Location extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$location='N/A';
try{
$ipAddress=@inet_ntop($row->getData($this->getColumn()->getIndex()));
if($ipAddress){
$data=file_get_contents("http://ipinfo.io/".$ipAddress."/json");
$locationData=json_decode($data,true);
if(isset($locationData['city'])){
$location=$locationData['city'].", ".Mage::app()->getLocale()->getCountryTranslation($locationData['country']);
}
}
}
catch(Exception $e){}
return $location;
}
}