Magento – Events and observers; what is being cached

event-observerfull-page-cachegeoipmagento-2.0.7magento2

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.

Best Answer

You can try another event controller_front_send_response_before

Related Topic