Jump to content
AlexandrZuyev

Customers IP and Geo Country info with order_confirmation email

Recommended Posts

@@ArtcoInc thank you Malcom.... I will definitely take a look at that.

 

I had the code already to make optional removing the column - but no test on install if he column existed (which made it rather useless.... a user could never reinstall if they choose to leave the column).

Share this post


Link to post
Share on other sites

Any option on removing the column on install? 

 

I'd leave the data as is.  It can't hurt anything...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Ok I made an error in my hook... carrying over code from the previous version that required edits to the order class.

	    global $order;
	  
	      $customers_ip = $order->customer['customers_ip'];

So, I have redone the hook to include its own query....

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  class hook_admin_orders_location {

    function listen_orderTab() {
      global $_GET;

          $customer_ip_query = tep_db_query("select customers_ip from orders where orders_id = '" . (int)$_GET['oID'] . "'");
		  $customer_ip_raw = tep_db_fetch_array($customer_ip_query);		
		  $customers_ip = $customer_ip_raw['customers_ip'];
	  
          $tab_title = Location;
          $tab_link = substr(tep_href_link('orders.php', tep_get_all_get_params()), strlen($base_url)) . '#section_location_content';

          $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$customers_ip"));

          $country = $geo["geoplugin_countryName"];
          $city = $geo["geoplugin_city"];
          $region = $geo["geoplugin_regionName"];
		  $latitude = $geo["geoplugin_latitude"];
		  $longitude = $geo["geoplugin_longitude"];

         
		 $output = <<<EOD
<script>
$(function() {
  $('#orderTabs ul').append('<li><a href="{$tab_link}">{$tab_title}</a></li>');
});
</script>

<div id="section_location_content" style="padding: 10px;">
 <p><strong>Customers Location: </strong>{$customers_ip}<br><br>{$country}<br>{$city}<br>{$region}<br>{$latitude}<br>{$longitude}</p> 
 
</div>
EOD;

      return $output;
    }
  }
?>

Share this post


Link to post
Share on other sites

@@burt, somewhat related question.... in my checkout_success content mod, to grab and store the customers IP address, you had suggested to use the built in function to get the IP.

   $customers_ip = tep_db_prepare_input(tep_get_ip_address());

In place of

    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
 
    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

Which I certainly understand.... however, have you noticed the built in function does not get IPV6 addresses?

 

I've noticed, by looking at "who's online", about 25% of customers online have a "blank" IP address... and now that I have moved this over to my live site also notice about 25% of the orders are have no IP.

 

I've drawn the conclusion - based on my original  code where 100% had an IP and about 25% of those IP's where IPV6 (I believe... example below)....

 

 

xxxx:1970:48e2:xx

 

Thoughts????

Share this post


Link to post
Share on other sites

Thoughts????

If you work with whats already there, then when core gets updated it automatically fixes itself. However as we all know, that can take a while.

 

Alternative is to make an inbuilt (in the module) function just for its own use... <--- this


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×