Magento EE – display global messages when you have Full Page Cache turned on

forcedisablefpc

Have you ever wanted to enable Magento global messages when you have Full Page Cache (FPC) turned on ? I wanted it, but after several hours of debugging and studying magento caching mechanism, i found it’s hard to punch a hole for Magento global message, i thought about an alternative solution – ignoring FPC when we have global message !

By default, when we add this GET parameter ‘?___store’ to request url, Magento will bypass caching and generate content from files, sessions and database for you. With this clue, we know what we need to do is to add ‘?___store’ parameter to redirect url so we can achieve our goal

In order to do that, you will need to override a controller that you want to display global message after have action in that controller done.

<frontend>
     <routers>
          <catalog>
               <args>
                    <modules>
                         <Wagento_Custom before="Mage_Catalog">Wagento_Custom</Wagento_Custom>
                    </modules>
               </args>
          </catalog>
     </routers>
</frontend>

Then you need to modify _redirectReferer function extended from Mage_Core_Controller_Varien_Action like this

<?php
/*include Mage_Catalog_Product_CompareController to extend it*/
require_once 'Mage/Catalog/controllers/Product/CompareController.php';

class Wagento_Custom_Product_CompareController extends Mage_Catalog_Product_CompareController
{
     protected function _redirectReferer()
     {
        $refererUrl = $this->_getRefererUrl();
        if (empty($refererUrl)) {
            $refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;
        }

          /*inject ignore global full page cache param*/
          if (!strpos($refererUrl, '?___store'))
          {
               $refererUrl .= '?___store';
          }
          /*end of hacking*/

        $this->getResponse()->setRedirect($refererUrl);
          //parent::_redirectReferer($url); // call _redirectReferer from Mage_Core_Controller_Varien_Action
        return $this;
     }
}

that’s it, we’ve done it in dirty way