Author - Robert Popovic

Founder and Technical Director of LERO9, a web agency specializing in Magento and WordPress design and development.

I launched Magebase in April, 2010 and am its editor and contributor. My main topics of interest are Magento development, customization and how to get the most out of Magento with the least amount of headache.

More Info » Follow me on Twitter »

Reader Comments (16)

  1. Andy
    Andy
    October 6, 2010 at 9:13 pm /

    Very nice article, Robert! I wish I could find it before.
    We’ve been trying to implement the same feature for our client’s store but then found a nice solution, very similar to yours. Store and currency auto switcher extensions by mageworx http://www.mageworx.com/store-and-currency-auto-switcher-magento-extension.html

    Reply
  2. nathan
    nathan
    December 11, 2010 at 3:48 am /

    This is AWESOME.. I don’t need to pay for an extension now… man you are great.

    I’ll make all my trademe related code public too soon when it’s done..

    So everyone are free to upload to trademe programtically…

    Cheers
    nathan

    Reply
  3. Anonymous
    December 21, 2010 at 7:40 am /

    [...] [...]

  4. Jo
    Jo
    March 29, 2011 at 9:06 am /

    Thank you!

    Reply
  5. nathan chen
    March 29, 2011 at 11:28 pm /

    oh this is awesome…. awesome…

    Reply
  6. Setting default values based on GeoIP data – Tutorials – Magebase

    [...] up on Robert’s article How To Set Default Store Currency Based On Visitor Country In Magento I wanted to take the concept in a slightly different direction: Firstly I wanted to have an [...]

  7. kannankrp
    kannankrp
    September 6, 2011 at 9:53 pm /

    Hi Robert,

    Thank you very much your useful article.

    Thanks and Regards,

    Kannan P

    Reply
  8. Palanikumar
    Palanikumar
    September 7, 2011 at 8:00 pm /

    Hi Robert,

    I tried your module. But am getting below fatal error
    “Fatal error: Call to undefined function geoip_country_code_by_name()”.

    Thanks
    Palanikumar
    Magento talks

    Reply
  9. Kannankrp
    Kannankrp
    September 7, 2011 at 9:04 pm /

    Hi Palani,

    Please check installation properly and also check php.ini file and php-geoip extension.

    Please check below mention URL:

    http://blog.thecodingmachine.com/content/installing-php-geolocalization-extension-centos

    Thanks and regards,

    Kannan

    Reply
  10. will
    January 10, 2012 at 5:28 pm /

    great module, and great explanation. Any idea how to switch between magento websites instead of currencies?

    happy new year

    Reply
  11. will
    January 11, 2012 at 10:21 am /

    thanks for the really quick reply, I have a switcher already built a bit differently as below. Sorry for confusion but I am trying to create an automatic website switcher as you said like in Stores > websites. I have a few different “magento websites” which I want to switch between based on what IP it is, I tried to extend website.php in a similar way to you have extended store.php by using function getDefaultStore() but this function is looking to return a magento object Mage_Core_Model_Store so not sure if this is the right way to do it. many thanks for the help

    <?php
    						$websites = Mage::getModel('core/website')->getCollection();
    						$i = 0;
    						foreach($websites as $website)
    						{
    						    $default_store = $website->getDefaultStore();
    						    $url_obj = new Mage_Core_Model_Url();
    						    $default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
    						?>
    						    <option name="<?php  $i++; echo $i; ?>"
    						    <?php if(strstr($this->helper('core/url')->getCurrentUrl(), $default_store_path)): ?>selected="selected"<?php endif; ?> value="<?php echo $default_store_path ?>"><?php echo $website->getName(); ?></option>
    						<?php
    						}
    						?>
    
    Reply
  12. will
    January 11, 2012 at 12:15 pm /

    thanks again but it is not the template I’m trying to change rather the way the ip directs the user to the right site in you function

    public function getDefaultCurrencyCode()
    {
       ......
    }
    

    the currency code is pulled from the geoip data and returned back to the store to dislay the currency code.
    I want to use the currency code from the geoip data to set what website the user is on. Maybe I am not doing this the right way, I had a search throught the code and couldn’t find any where any function like getDefaultWebsite so have been trying it with

    getDefaultStore()
    
    Reply

Add a Comment & Join the Discussion

Insert small snippets of code by using [code]{your_code_here}[/code]
For larger code blocks please use http://pastebin.com and paste your link.

You may also use the following HTML in your comment: <a href="" title=""> <abbr title="">
<acronym title=""> <blockquote cite=""> <cite> <em> <strike> <strong>