{"id":680,"date":"2013-06-25T10:48:39","date_gmt":"2013-06-25T10:48:39","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=680"},"modified":"2013-06-25T10:48:39","modified_gmt":"2013-06-25T10:48:39","slug":"magento-e-display-global-messages-when-you-have-full-page-cache-turned-on","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/magento-e-display-global-messages-when-you-have-full-page-cache-turned-on\/","title":{"rendered":"Magento EE – display global messages when you have Full Page Cache turned on"},"content":{"rendered":"
<\/p>\n
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 !<\/p>\n
<\/p>\n
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<\/p>\n
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.<\/p>\n
\n<frontend>\n <routers>\n <catalog>\n <args>\n <modules>\n <Wagento_Custom before="Mage_Catalog">Wagento_Custom<\/Wagento_Custom>\n <\/modules>\n <\/args>\n <\/catalog>\n <\/routers>\n<\/frontend>\n<\/pre>\nThen you need to modify _redirectReferer function extended from Mage_Core_Controller_Varien_Action like this<\/p>\n
\n<?php\n\/*include Mage_Catalog_Product_CompareController to extend it*\/\nrequire_once 'Mage\/Catalog\/controllers\/Product\/CompareController.php';\n\nclass Wagento_Custom_Product_CompareController extends Mage_Catalog_Product_CompareController\n{\n protected function _redirectReferer()\n {\n $refererUrl = $this->_getRefererUrl();\n if (empty($refererUrl)) {\n $refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;\n }\n\n \/*inject ignore global full page cache param*\/\n if (!strpos($refererUrl, '?___store'))\n {\n $refererUrl .= '?___store';\n }\n \/*end of hacking*\/\n\n $this->getResponse()->setRedirect($refererUrl);\n \/\/parent::_redirectReferer($url); \/\/ call _redirectReferer from Mage_Core_Controller_Varien_Action\n return $this;\n }\n}\n<\/pre>\nthat’s it, we’ve done it in dirty<\/em><\/strong> way<\/p>\n","protected":false},"excerpt":{"rendered":"
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…<\/p>\n