{"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":"

\"forcedisablefpc\"<\/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>\n

Then 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>\n

that’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

Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[59,61,62,51],"aioseo_notices":[],"views":5,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/680"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":0,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}