0

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

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89

1 Answers1

1

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.

PixieMedia
  • 1,548
  • 1
  • 9
  • 15
  • Thank you so much PixieMedia. The problem I encounter observing tha event is that, if a redirect is needed, the redirect instruction is not executed my Magento. I used header('Location: domain') and also Magento setRedirect but no luck – Alessandro Di Maggio Oct 20 '15 at 12:46
  • try: Mage::app()->getResponse()->setRedirect($url); – PixieMedia Oct 20 '15 at 12:58
  • Still not working. I debugged a little deeper, when a page is served by the FPC the only events triggered are http_response_send_before and http_response_send_after but observer is not executed – Alessandro Di Maggio Oct 20 '15 at 13:37
  • what version of Magento EE are you using? this 100% works fine in EE 1.14.1 – PixieMedia Oct 20 '15 at 16:01
  • could be your other code isnt working correctly, try sticking Mage::log('FIRED',null,'events.log'); in the observer function, clear all caches - including opcache if that is on the server, and nginx if you are using that with sendfile switched on, and go hit the site multiple times. the /var/log/events.log should keep growing – PixieMedia Oct 20 '15 at 16:03
  • Thank you for your support PixieMedia. I solved placing a Block before the header. The block is never cached and it works. – Alessandro Di Maggio Oct 21 '15 at 13:04
  • no problem, im still confused as to why my solution didnt work for you as it works perfectly on the EE site we've just finished. Anyway, glad you found a solution – PixieMedia Oct 21 '15 at 13:28