Geolocation redirect per country

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 9 ans
Hello to all,
i am looking forward to find a solution how we can redirect visitors from specific countries to another domain?
This is the method of Geolocation as i have already read but i didn't manage to implement it.

We use Nop 3.4 Version, if somebody can do it for me, let suggest me a price for this job and we will discuss it.

Thanks in advance.
Il y a 9 ans
tecnopneumatic wrote:
Hello to all,
i am looking forward to find a solution how we can redirect visitors from specific countries to another domain?
This is the method of Geolocation as i have already read but i didn't manage to implement it.

We use Nop 3.4 Version, if somebody can do it for me, let suggest me a price for this job and we will discuss it.

Thanks in advance.


Hi,
If I in your shoes, I'm do this in Application_BeginRequest() method in Global.asax

1- Resolve IGeoLookupService
2- Call LookupCountryIsoCode(string ipAddress) method
3- Apply 302 redirect prior to returned CountryIsoCode

Maybe there is a different way. This is first solution that comes to my mind :)
Il y a 9 ans
I used a actionfilter plugin against certain controllers in my use case.  Leveraged the geoservice, and then stored the result in a custom attribute for the customer. This way, when they returned, I could do a quick lookup in their custom attributes rather than doing a geo lookup.
So essentially,
1. User comes to site
2. Action filter routine checks to see if this user has custom attributes (key pair) for geolocaiton
3. if not, do a lookup and store it for quick reference on future visits
4. actionfilter redirects to where you want the user... if they are ok to be on the specific site, do nothing, otherwise, have your action filter redirect them to the target site.

That's basically it...and it can all be done from a plugin, no need to touch the core code.
Il y a 8 ans
Hello

I sent you PM.

Let me know if you interested.
Il y a 3 ans
We can redirect country vise like below in Nop version 4.0 and above. You can add OnActionExecuting in Base controller like below.

public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var _workContext = EngineContext.Current.Resolve<IWorkContext>();
            var _storeContext = EngineContext.Current.Resolve<IStoreContext>();            
            var _webHelper = EngineContext.Current.Resolve<IWebHelper>();
            var _logger = EngineContext.Current.Resolve<ILogger>();
            var geo = EngineContext.Current.Resolve<IGeoLookupService>();
      
            string country = geo.LookupCountryIsoCode(_webHelper.GetCurrentIpAddress());
            _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "Country Origin", country, _workContext.CurrentCustomer);

            if (!string.IsNullOrEmpty(country))
            {
                if (country.Equals("US") && _storeContext.CurrentStore.Hosts.ToLower() != "abc.com")
                {
                    _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "Redirection To US Country:" + country, _webHelper.GetCurrentIpAddress(), _workContext.CurrentCustomer);
                    filterContext.Result = new RedirectResult("http://abc.com");
                    return;
                }
                if (country.Equals("CA") && _storeContext.CurrentStore.Hosts.ToLower() != "def.com")
                {
                    _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "Redirection TO CA Country:" + country, _webHelper.GetCurrentIpAddress(), _workContext.CurrentCustomer);
                    filterContext.Result = new RedirectResult("http://def.com");
                    return;
                }
                if (country != "CA" && country != "US")
                {
                    if (_storeContext.CurrentStore.Hosts.ToLower() != "site.com")
                    {
                        _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "Redirection to other Country:" + country, _webHelper.GetCurrentIpAddress(), _workContext.CurrentCustomer);
                        filterContext.Result = new RedirectResult("http://site.com");
                        return;
                    }
                }
            }
        }

User can change as per requirement.
Il y a 3 ans
Hi,
Hope you are well,

PM sent, please let me know if you have something to share.

BR,
Maria J
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.