1

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 !

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.