Chillax86 Posted September 25, 2013 Share Posted September 25, 2013 (edited) Hi all, I need to redirect anyone that is outside of the UK to our other world-wide shop, so the solution I drummed up was to add the code below to restricted-country.tpl {if ({$lang_iso} == 'gb')} <script type="text/javascript"> window.location.href = "http://www.simplicitycomputers.co.uk/store"; </script> {else} <script type="text/javascript"> window.location.href = "http://www.simplicitycomputers.co.uk/store/worldwide/"; </script> {/if} But this is very buggy and isn't working quite right, I think this is because the if statement is relying on the browsers choice of language which isn't what I needed. Does anyone have any idea how this could be done by IP the same way i think prestashop does it Edited September 29, 2013 by Chillax86 (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted September 25, 2013 Share Posted September 25, 2013 you could do this using your .htaccess #The 'Accept-Language' header starts with 'gb' #and the test is case-insensitive ([NC]) RewriteCond %{HTTP:Accept-Language} ^gb [NC] #Redirect user to gb shop address #sending 301 (Moved Permanently) HTTP status code RewriteRule ^$ (insert redirect url here) [L,R=301] if you are unfamiliar with updating the ps generated copy of .htaccess see this post www.prestashop.com/forums/topic/2131[spam-filter]tip-15-and-custom-htaccess/ Link to comment Share on other sites More sharing options...
El Patron Posted September 25, 2013 Share Posted September 25, 2013 tip; A much better solution is to create a shop (using multistore) for each country you do business in...i.e. .com/.uk/.fr/.de etc. 1 Link to comment Share on other sites More sharing options...
Chillax86 Posted September 25, 2013 Author Share Posted September 25, 2013 (edited) Thank you for your reply's. Really I would like to use the geolocation feature to do this if I can. I have been nosing around in the FrontController.php and I found this protected function displayRestrictedCountryPage() { header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign('favicon_url', _PS_IMG_.Configuration::get('PS_FAVICON')); $this->smartyOutputContent(_PS_THEME_DIR_.'restricted-country.tpl'); exit; } and I found a section that grabs the country_name in the geolocationManagement($default_country) function include_once(_PS_GEOIP_DIR_.'geoipcity.inc'); $gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD); $record = geoip_record_by_addr($gi, Tools::getRemoteAddr()); What I would like to do is override the FrontController.php and change displayRestrictedCountryPage() function to protected function displayRestrictedCountryPage() { header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign(array('favicon_url', _PS_IMG_.Configuration::get('PS_FAVICON'), 'geolocation_country' => $record->country_name); $this->smartyOutputContent(_PS_THEME_DIR_.'restricted-country.tpl'); exit; } once the right value is assigned I can then do a smarty if statement to redirect to the right site my problem now is trying to assign the right value to $geolocation_country I'm guessing that i have to change all occurrences of $record to $this->record inside the geolocationManagement($default_country) function in order for me to assign the right value within displayRestrictedCountryPage() using $this->record->country_name. hopefully this will work but when i tried it with an override by copying FrontController.php to the classes override directory it did not work. Is this because overrides can only add functionality not override, so do i have to edit the core files for this method to work. Edited September 25, 2013 by Chillax86 (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted September 25, 2013 Share Posted September 25, 2013 when you manually install an override, you must delete the file "class_index.php" in cache folder. 1 Link to comment Share on other sites More sharing options...
Chillax86 Posted September 27, 2013 Author Share Posted September 27, 2013 Thanks that has worked a treat, I'm now overriding. Link to comment Share on other sites More sharing options...
sbweb Posted June 21, 2017 Share Posted June 21, 2017 Hi Chillax86 Can you write the whole solution down and post it in the forum, so other were able to replicate it on their own shops?. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now