Jump to content

[SOLVED]Redirect to another shop if not located in the UK


Chillax86

Recommended Posts

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">
</script>
{else}
<script type="text/javascript">
</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 by Chillax86 (see edit history)
Link to comment
Share on other sites

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

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 by Chillax86 (see edit history)
Link to comment
Share on other sites

  • 3 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...