1

I am using Cloudflare to retrieve the Geo IP of a user.

When using this in pub/index.php it always works and I am able to set the correct store view based on the header Cloudflare is passing.

However, this doesn't seem good practice (and it is ignored in my repository too). So that's why I'm trying to do it correctly via this observer:

<event name="controller_action_predispatch">
    <observer name="elephant_cfparent_controller_redirect" instance="Elephant\CFParent\Model\ObserverGeoIP" />
</event>

However, this is being cached, resulting in an incorrect store view for a user in another country. Is anyone aware on how I can do this without cache? Or am I using the wrong event name for example?

Cache is normal Magento FPC (no Varnish) and I'm on Magento 2.0.7.

2

You can try another event controller_front_send_response_before

| improve this answer | |
1

Use around plugin on \Magento\Framework\App\FrontControllerInterface::dispatch method and do redirect without call dispatch method.

| improve this answer | |
  • Cheers. That should work too. I found out that the event works though, but my code was wrong. D'oh! But I'll leave this question and the answer for if someone ever wonders how this works. – TommyK May 31 '16 at 8:56
  • @ToomyK i am getting same issue as my controller_action_predispatch event get cached and my code does not execute for second time – Satish Dubariya Jul 10 '19 at 11:59
  • @TommyK, were you able to fix the issue? I am using Varnish and my observer is not being called when the cached content is loaded. – anujeet Jun 11 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.