0

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.

3
  • Do you mean you need country name corresponding to that IP Address? Commented Dec 4, 2016 at 13:07
  • @piyush_systematix Yes. Country and if possible city.
    – Rocky Sinh
    Commented Dec 4, 2016 at 13:53
  • City or Country of customer seeing website.
    – Rocky Sinh
    Commented Dec 4, 2016 at 13:54

1 Answer 1

0

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;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.