2

I want to add a radio button with the following option

Show product in

> United States
> International
> Both

Upon selection the product will show on the front end for the appropriate customers using IP detection

I google it and i found one plugin

http://www.magentocommerce.com/magento-connect/Vinay.N+%28+Tumkur%2CKethohalli%29/extension/2413/product-by-ipaddress

But it is not compatible with Magento ver. 1.5.0.1. Please help. Thanks

Vasanthan.R.P
  • 1,277
  • 1
  • 19
  • 46

1 Answers1

5

Setup two websites for your shop, where 'website' does not have to mean a different URL, just, internally for Magento it is a 'website'. For this example use codes 'usd' and 'row'.

Use GeoIP in Apache if you can install packages on your distro. If not then you can use PHP geoip plugins - again see what is recommended for your setup.

To send your customers to what Magento thinks is a website, with the site visitor not knowing they have been 'redirected'. In your index.php you will need something like:

$country=$_SERVER['GEOIP_COUNTRY_CODE'];
switch ($country)
{ case "CA":
  case "MX":
  case "US":
    $_SERVER['MAGE_RUN_CODE'] = "usd";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
    break;
  default:
    $_SERVER['MAGE_RUN_CODE'] = "row";
    $_SERVER['MAGE_RUN_TYPE'] = "store";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);

For your products, in the website tab, select the websites that you want the product to show in. Put a tick in both boxes or just one depending on how it is to show.

This will be easy to update compared to a 'hacked' solution.

Update.

The sleekest way to run GeoIP is as an apache module. Here is the link to the instructions and download:

http://www.maxmind.com/app/mod_geoip

If installing an Apache module is not possible due to shared hosting or operating system flakiness then the PHP module can be used instead. Full instructions and download for geoIP can be found here:

http://www.maxmind.com/app/php

Once installed swap out $country=$_SERVER['GEOIP_COUNTRY_CODE']; for the following:

include("geoip/geoip.inc");

// Uncomment if querying against GeoIP/Lite City.
// include("geoipcity.inc");

$gi = geoip_open("/your/path/to/geoip/GeoIP.dat",GEOIP_STANDARD);
$country=geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

More help on GeoIP is available from the above links.

ʍǝɥʇɐɯ
  • 4,012
  • 7
  • 32
  • 53
  • This is what i really need. Than you very much, I have some problems. $_SERVER['GEOIP_COUNTRY_CODE'] is not working in my server so i have to find out some other options. Also i have to assign 1000s of products to the newly created website. Is there any easy way to do it. Please advise. Thanks – Vasanthan.R.P May 26 '11 at 10:48
  • You can assign products to the two websites very easily from the catalog admin page - select the products you want and choose update attributes from the dropdown. – ʍǝɥʇɐɯ May 26 '11 at 11:00
  • I has updated my answer to include the links to geoip instructions and downloads. – ʍǝɥʇɐɯ May 26 '11 at 11:09