Magento Geolocalization/FPC

112 views Asked by At

In Magento EE I need to redirect customers depending Origin country, browser lang and previous preference set in a cookie.

I have huge problems making it work with FPC.

I tryed to observe the controller_action_predispatch event, but FPC somehow caches my redirect instruction and customer is not redirected.

I then tried another solution: extending the run() method in Mage_Core_Model_App in order to perform operations before FPC starts to work.

Unfortunately, I don't know why, inside this method you can't access Mage::getModel(), Mage::helper(), Mage::getConfig() ecc

Can you help me please?

Thank you

1

There are 1 answers

7
PixieMedia On

I've recently been through exactly the same pain. You are on the right track;

controller_action_predispatch

Is the correct event to observe, and you can use this quite happily if you are redirecting to a category or product page with FPC enabled. The problem is the home page - which is a cms page. The cms page cache does not fire controller_action_predispatch. I got around this by adding this to my observer;

public function switchUser($event)
{

// CMS page bug, disable FPC to still use observer
    $action = $event->getEvent()->getControllerAction();
    if($action instanceof Mage_Cms_IndexController) {
         $cache = Mage::app()->getCacheInstance();
         $cache->banUse('full_page');
     }
// do the rest of your code here
}

The blocks within the cms page will still cache so the page is still nippy, though obviously not as fast as it would be with full FPC enabled. Its a sound trade off in my opinion.