stopshop Posted November 5, 2008 Share Posted November 5, 2008 HiIs it at all possible that the site could automatically change the currency to accommodate the visitor, depending on the geographical location of his/her ip address?I am currently using 3 currencies on the shop, USD, Euros & ZAR.It would be great if the shop would automatically shift to Euros or ZAR (USD as default currency) if the visitor was coming from Europe or South Africa.Any help/suggestion is appreciated.Cheers Link to comment Share on other sites More sharing options...
d0m1n1k Posted November 5, 2008 Share Posted November 5, 2008 http://at2.php.net/manual/en/function.geoip-country-code-by-name.phpthis returns the country code for a specific ip or hostname.the rest should be easy (check if country code is like ... and set cookie vars for language and currency)greetings Link to comment Share on other sites More sharing options...
stopshop Posted November 5, 2008 Author Share Posted November 5, 2008 Thanks for the reply, but I'm totally lost here.Could you perhaps send me in the right direction (where I may find full instructions to achieve this)?Thanks Link to comment Share on other sites More sharing options...
stopshop Posted November 6, 2008 Author Share Posted November 6, 2008 Anyone?Please help if you can, thanks. Link to comment Share on other sites More sharing options...
d0m1n1k Posted November 6, 2008 Share Posted November 6, 2008 tools.php static public function setCurrency()so in init.php somewhere after tools::setCookieLanguage();you write something like: $hack_ArrCountryCurrency = ('de' => 'eur', 'us' => 'usd', ...); $hack_countryCode = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']); if (array_key_exists($hack_countryCode, $hack_ArrCountryCurrency )) tools::setCurrency($hack_ArrCountryCurrency[$hack_countryCode]); greetings Link to comment Share on other sites More sharing options...
stopshop Posted November 6, 2008 Author Share Posted November 6, 2008 Thanks for the reply, much appreciated.Ok, I'm not too clued up with php's etc.., but I do edit a few files using FP on a regular basis.So can I just basically paste the code into the tools.php file (anywhere in the file?), then just upload/replace existing one?I will backup the original tools.php..Thanks for your help. Link to comment Share on other sites More sharing options...
d0m1n1k Posted November 6, 2008 Share Posted November 6, 2008 may work, or not i haven't tested this piece of code by myself.i'd put it between line 22 and 23 (may vary if your ps version isn't cvs 6395).it could also be that you have to put some files for the geoip thing on your server (i haven't used this thing too) Link to comment Share on other sites More sharing options...
stopshop Posted November 6, 2008 Author Share Posted November 6, 2008 Damn, wouldn't it be nice if this was included in PS..I'll do some more searching and share my results should anything good come up.Cheers Link to comment Share on other sites More sharing options...
d0m1n1k Posted November 6, 2008 Share Posted November 6, 2008 create a feature request and include a link to this post Link to comment Share on other sites More sharing options...
stopshop Posted November 7, 2008 Author Share Posted November 7, 2008 I have created a feature request, but would still like to have this before PS decides (or not) to implement it.Can anyone help out please? Link to comment Share on other sites More sharing options...
Doulas Akula Posted February 8, 2013 Share Posted February 8, 2013 I did it for my site and it worked. Here is how I went about it. Prestashop cookies,variables are loaded through the front controller class found in the class folder when the site loads. So it is very easy to dictate the currency cookie at this point. You will need to write a function in Tools class and also Front controller. So in front controller just after $currency = Tools::setCurrency(); edit that line and paste the following piece of code $countrycode = $this->countryBasedOnIp(); global $currency; if ($countrycode == 'KE') { $currency = Tools::setCurrencyKenyan(); } elseif ($countrycode != 'KE' ) { $currency = Tools::setCurrency(); Then in front controller you will need to have the countryBasedOnIp() function which looks like this; public static function countryBasedOnIp () { global $currency; /* Check if Maxmind Database exists (For more info on Maximind check their website) */ if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat')) { include_once(_PS_GEOIP_DIR_.'geoipcity.inc'); include_once(_PS_GEOIP_DIR_.'geoipregionvars.php'); $gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD); $record = geoip_record_by_addr($gi, Tools::getRemoteAddr()); } return $record->country_code; } Then in tools.php you will create a function that return the exact currency cookie you need.In my case it was the Kenyan currency cookie.So the function looks like this. public static function setCurrencyKenyan() { global $cookie; $currency = Currency::getCurrencyInstance((int)(4)); if (is_object($currency) AND $currency->id) $cookie->id_currency = (int)(4); //you have to assign the exact currency id return $currency; } I hope this helps somebody out there Link to comment Share on other sites More sharing options...
El Patron Posted February 8, 2013 Share Posted February 8, 2013 (edited) another way is to simply turn on GeoLocation, then in shipping-->countries-->edit the country, set the currency default for that currency..then native geolocation will set the visitors currency to that set in the countries default currency... Edited June 18, 2013 by eTiendas.co (see edit history) Link to comment Share on other sites More sharing options...
Doulas Akula Posted February 8, 2013 Share Posted February 8, 2013 Thanks Elpatron for sharing this. 1 Link to comment Share on other sites More sharing options...
Doulas Akula Posted February 18, 2013 Share Posted February 18, 2013 I tried geolocation by IP adress using the ciuntries sub-tab but it is not working for me. I need to get right becuase it might be holding the solution to a bug am facing with my earlier option. The default currency still shows up. I have changed the default currency for the shop under shipping >> countries >> then selected country Kenya and changed the default currency to KSHS. i have also enabled Geolocation. Anything am missing ? Link to comment Share on other sites More sharing options...
El Patron Posted February 18, 2013 Share Posted February 18, 2013 try this-->clean your cookies from your browser...as it remembers the last currency you selected.. this assumes you do not have your code (hack) messing things up... also you need to set the country default currency...1.4 shipping-->countries-->edit the country-->select the default currency Link to comment Share on other sites More sharing options...
tomerg3 Posted February 18, 2013 Share Posted February 18, 2013 You can check out http://www.prestasho...ching-language/ It works using a local file system rather than DB, which is faster, and also uses a IP 2 location list that is updated daily, so you can download and install the new list as often as you wish. Link to comment Share on other sites More sharing options...
El Patron Posted February 19, 2013 Share Posted February 19, 2013 I also have a module...controls the visitors both logged and non-logged cookie country based on their IP, http://www.prestashop.com/forums/topic/187339-module-prestashop-geo-pricing-product-pricing-by-country/ Link to comment Share on other sites More sharing options...
Recommended Posts