Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site suggestion is remembering the last country site, not my IP country site #13

Closed
amityweb opened this issue Jul 11, 2019 · 2 comments

Comments

@amityweb
Copy link

amityweb commented Jul 11, 2019

Hi

The wrong site is being suggested when we visit a new site. Its suggesting the previous site I was on, not the site where my IP is.

So for example, I am in the UK and I visit the US site, it pops up at first asking if I want to visit the US site or the UK site, all OK.

Lets say I go to the USA, not my country site which is UK.

If I then use the site switcher, which is your code, to go to say Italy, and I manage to get the popup again, it would ask if I want to go to the USA site or the Italy site. If I go to Italy and then a new country site and then get the switcher it asks me if I want to go to the Italy site or the new site.

So the site info in craft.geomate.redirectInformation() is remembering the last site I was on, NOT the site for my IP address.

Full code:

{% set redirectInfo = craft.geomate.redirectInformation() %}
	
{% if redirectInfo %}

	{% set targetSiteSettings = craft.app.globals.getSetByHandle('siteSettings', redirectInfo.site.id) %}
	{% set currentSiteSettings = craft.app.globals.getSetByHandle('siteSettings', currentSite.id) %}
	
	{% set currentCountryFlag = currentSiteSettings.countryFlag.first() %}
	{% set targetCountryFlag = targetSiteSettings.countryFlag.first() %}
	

	<div class="reveal" id="countryRedirectPopup" data-reveal>

		<p>{{ strings('Please select the country version of the website you would like to view')}}</p>
		
		<br/>
		
		<a href="{{ redirectInfo.url | addOverrideParam }}"><img src="{{ targetCountryFlag.url }}" width="30" height="20"> {{ redirectInfo.site.name }}</a>
		
		<br/>
		<br/>
		
		<a href="{{ currentSite.baseUrl | addOverrideParam }}"><img src="{{ currentCountryFlag.url }}" width="30" height="20">{{ currentSite.name }}</a>
		
		<br/>
		<br/>

		<button class="close-button" data-close aria-label="Close modal" type="button">
			<span aria-hidden="true">&times;</span>
		</button>

	</div>


{% endif %}

Config:

return [
	'redirectMap' => [
	    'uk' => 'gb',
	    'us' => 'us',
	    'de' => 'de' ,
	    'ko' => 'ko',
	    'it' => 'it',
	    'es' => 'es'	
	],
];

Thanks

@aelvan
Copy link
Contributor

aelvan commented Jul 13, 2019

Yes, that is the intended behavior. If the user has selected a site as their preferred site, GeoMate assumes that that's the site that the user prefers. You can check redirectInfo.isOverridden to see if that's the case.

You can also use craft.geomate.isOverridden to check if the user has manually selected a site. If he has, you probably shouldn't show the popup at all.

@amityweb
Copy link
Author

amityweb commented Sep 9, 2019

Sorry for late reply, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants