As a part of my functionality, using below I'm dispatching a conditional error message.
<event name="controller_action_predispatch">
<observer name="controller_post_dispatch_sessionTimeout_message" instance="AAMC\Customer\Observer\SessionTimeoutMessage" />
</event>
public function execute(\Magento\Framework\Event\Observer $observer)
{
if(!$this->customerLoggedIn() && $this->_cookieManager->getCookie(CustomerHelper::LOGGED_IN_COOKIE)){
$this->_cookieManager->deleteCookie(
CustomerHelper::LOGGED_IN_COOKIE,
$this->_cookieMetadataFactory
->createCookieMetadata()
->setPath($this->_sessionManager->getCookiePath())
->setDomain($this->_sessionManager->getCookieDomain())
);
$this->_messageManager->addErrorMessage('Session time out. Please login to continue');
}
}
Messages are displaying only in uncacheable
pages like customer, checkout but it failed to display messages in cacheable pages
like home, product listing, product detail etc.
I've verified the same by disabling cache. Any help will be appreciated !