Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Automatic currency change with each country specific IP address. 
 
megamagento
Jr. Member
 
Total Posts:  11
Joined:  2009-03-09
 

Hi

Is there a method for changing the way Magento displays currencies? So, for example, when a US customer arrives at a page it is displayed in USD automatically. On the same page a UK customer would see GBP, a Canadian customer would see CAD, a French customer EUROs etc without them having to change anything. So the currency displayed depends on the customers IP location.

I know this is possible on OSCommerce. See here: http://addons.oscommerce.com/info/6450

I have USD, GBP and CAD currencies on my site with the default selector, but most of the visitors from the US and Canada bounce straight off the site once they see GBP is the default landing currency for the site. They don’t seem to even look to change the currency so I am loosing a lot of potential sales. It would be great if this was built in to Magento out of the box and configurable in the backend.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
fegizii
Sr. Member
 
Total Posts:  160
Joined:  2009-01-21
 

I’d be interested in the same… maybe if we find enough ppl we could hire a developer

 
Magento Community Magento Community
Magento Community
Magento Community
 
megamagento
Jr. Member
 
Total Posts:  11
Joined:  2009-03-09
 

My site is currently a straight forward setup with one store and a single store view. The only language is English currently but it does have three different currencies available from the manual section drop down.

 
Magento Community Magento Community
Magento Community
Magento Community
 
megamagento
Jr. Member
 
Total Posts:  11
Joined:  2009-03-09
 

Great!

Thanks for the reply.

The second option you described sounds exactly like what I was trying to achieve. I’ll try it as soon as I get the chance.

Thanks for your efforts.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ian M
Jr. Member
 
Total Posts:  25
Joined:  2008-01-16
 

Hi dd_gi,

Many thanks for your code examples using GeoIP. My Magento setup is 1 website with 1 store with 3 store views. The store views are:-
International Store (Currency USD), European Store (Currency EUR) and United Kingdom Store (Currency GBP). I need the store views set-up this way for tax reasons and template layouts.

I have a couple of issues that I would be grateful if you could help with:-

My first is that I am not using the store codes in the URL (Config->Add Store Code to Urls=NO) therefore the example doesn’t work for me as I get 404 page not found errors using the code

[removed] \"$host/eur/$request\"

Is there a way round that issue?

Also from what I can tell, the code checks which country you are in via GeoIP lookup and then chooses the store view based on that country code. This check is performed each time a page view is generated. This is OK for most visitors, however I still need the customer to be able to manually change the store view if the IP location they are in is not correct.

Is there a way of checking the IP location just once and storing that value therefore reducing overheads of continually checking the IP address but more importantly, allowing a visitor to override (by selecting a different store view) the store view they require?

Many thanks in advance.

Ian

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ian M
Jr. Member
 
Total Posts:  25
Joined:  2008-01-16
 

Hi dd_gi,

My site (which is still in development) is http://www.gdatastore.com

If you select “GDATA Business” you will see some products with prices. You can then change the store view to International, European or UK and the currency should also change but the URL stays the same!

I haven’t modified any Magento code to get it to work in this manner, just selected “Add Store Code to Urls” to No.

Thanks once again for your help.

Ian

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ian M
Jr. Member
 
Total Posts:  25
Joined:  2008-01-16
 

Hi dd_gi,

Thanks for your latest post. I tried using the code example but I’m getting :-

Fatal error: Uncaught exception ‘Exception’ with message ‘Notice: Undefined index: USD

on the line

return $stores['USD'];

I’m still a novice with PHP but am learning fast! What does the following code line do?

$stores Mage::app()->getStores(falsetrue);

Thanks,

Ian

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

Hi dd_gi
Thank you for sharing your code. It looks very promising, however, for some reason I can’t get it working properly. I am working on the website with one store and two store view (USD and CAD) . We have some products that can be sold only in US or Canada, so the goal is two show USD store view for people in US and CAD for Canadians.
When I saw your first solution for Mage Magento I thought that this is exactly what I need, however, it looks like the code that is supposed to be included in header.php does not return the right url….

I am not sure what url I need but i know it should start like that:http://ourhost.ca/clients/oursite/
However, when I try to implement you code I get something like http://ourhost.ca/en/ents/oursite/ - which is completely wrong.

I also tried the solution that you suggested for lan_m, but the code doesn’t seem to affect the website at all. If I set US as my default store view, i end up on the us site, though my IP address is Canadian. Am I missing something here? Do i have to change any other files except for index.php?
I am using Magento 1.3.2.2
I am still new to Magento, so I feel a bit lost…Many thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

Yes, this is exactly what I want. I have 1 store and two store views (CAN and USD). USD is set as the default store view. However, when somebody with Canadian IP opens the website, he should see CAN store view NOT default USD store. But when I try to test it from Canada, i end up on USD store view....(this happens when I tried to implement the solution you offered Lan_M). When I tried the other solution that also involved changing header.phtml i started to get errors....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

Hi dd_gi

Many thanks for your help! I was finally able to get lan_w solution working! Part of the problem was that I did not include subfolder in the following link:
if ($_SERVER[’REQUEST_URI’] === ‘/subfolder/’ || $_SERVER[’REQUEST_URI’] === ‘/subfolder/index.php’) . However I also had to turn On “Add Store Code to Urls” in Configurations ->Web ->Url Options and reference “store code” (which I set to be different from store view name) in the following part of the code:
if($country==’CA’){
return $stores[’cad’];
}


else {
return $stores[’usd’];
}
code]

By the way, I also tried to get header.phtml code working but no matter what I try I get the following error
Parse error: syntax error, unexpected $end in /var/www/vhosts/purefire.ca/httpdocs/clients/expressvibe/app/design/frontend/default/default/template/page/html/header.phtml on line 87. I tried to figure out where its coming from but no luck. From what I can see all tags are close and all brackets are in places…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

Here you go…

<?php
include("/usr/local/share/GeoIP/geoip.inc");
$gi geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);
$country geoip_country_code_by_addr($gi$_SERVER['REMOTE_ADDR']);
$store substr($_SERVER['REQUEST_URI'=== '/clients/oursite/',0,5);

if(isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'){
    $host
='https://'.$_SERVER['SERVER_NAME'];
else {
    $host
='http://'.$_SERVER['SERVER_NAME'];
}
geoip_close
($gi);
if(
$country=='US' && $store!='/usd/'){
    
echo "
    <script type=\"
text/javascript\">
    <!--
    window. location = \"
$host/clients/oursite/usd/
    //-->
    </script>"
;
elseif($country=='CA' && $store!='/cad/'){
    
echo "
    <script type=\"
text/javascript\">
    <!--
    window. location = \"
$host/clients/oursite/cad/
    //-->
    </script>"
;

}
?> 

<div class="header-top-container">
<
div class ="header-image"> &nbsp;</div>
    <
div class="header-top">
        <
h1 id="logo"><a href="<?php echo $this->getUrl('') ?>"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
        <
class="no-display"><a href="#main"><strong><?php echo $this->__('Skip to Main Content'?> &raquo;</strong></a></p>

        <
div class ="header_empty">
                   <
div class="shop-access">
                
<?php echo $this->getChildHtml('topLinks'?>
            
</div>
                 
<?=$this->getLayout()->getBlock('top.search')->toHtml()?>
             
        
</div>






    </
div>
</
div>
<?php echo $this->getChildHtml('topMenu'?>

Once again, thanks a lot!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ins0
Member
 
Avatar
Total Posts:  38
Joined:  2008-03-26
 

Poor German AOL Users.... Each AOL Customer, it is a German or something else, get an American IP Address.
I would use the Browser Accept-Language ($_SERVER[’HTTP_ACCEPT_LANGUAGE’])

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

Thanks dd_gi,

I am going to try that.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hmeli
Jr. Member
 
Total Posts:  9
Joined:  2009-07-16
 

No luck...still not working. The home page starts looping in homepage-loading-homepage loop once I add the code to header

 
Magento Community Magento Community
Magento Community
Magento Community
 
phlux0r
Member
 
Avatar
Total Posts:  73
Joined:  2008-03-09
Auckland, New Zealand
 

If you’re running a single store/store view only and have the currency selector available and want to set the default currency depending on GeoIP, then I have a slightly different solution to the one dd_gi posted here: http://www.magentocommerce.com/boards/viewreply/179902/

My solution sets the default currency depending on geoIp and still allows the visitor to change the selection in the currency drop-down. There are no redirects either.

What I’ve done is basically override Mage_Core_Model_Store->getDefaultCurrencyCode() and use the geoIp functions to determine the currency I want selected based on the visitor’s country.

When a visitor comes to the site, their currency will be set according to their country/region but they will still be able to change it. Once they change it, their session cookie will be updated and the changed currency kept for the browsing session.

Hope this helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageWorxcom
Guru
 
Avatar
Total Posts:  410
Joined:  2009-06-03
Washington DC Metro Area, US
 

Hi,

There is a paid extension for this

https://www.magentocommerce.com/magento-connect/currency-auto-switcher-geoip-location-4768.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2