1

I'm using

<event name="controller_action_predispatch">

This event not working when I refresh category page second time .

If anyone knows please explain me.

public function saveVisitorData()
    {      
        $currentUrl = $this->_urlInterface->getCurrentUrl();       
        $s = $this->sValues();      
        $this->setUrl($currentUrl);     
        $this->setS1($s[1]);
        $this->setS2($s[2]);
         $this->save();
          }
 public function getCookieValue($val)
    {
        $value = $this->_cookieManager->getCookie($val);
        return $value;
    }  
    public function setCookie($cn, $v1)
    {
        $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(static::COOKIE_LIFETIME)->setPath($this->sessionManager->getCookiePath())->setDomain($this->sessionManager->getCookieDomain());        
        $this->_cookieManager->setPublicCookie($cn, $v1, $metadata);

    }

public function sValues()
    {
        $s = array();

        $s[1] = $this->_request->getParam('s1');
        $s[2] = $this->_request->getParam('s2');
        if ($s[1]) {
            $this->setCookie(self::COOKIE_s1, $s[1]);
        } else {
            $s[1] = $this->getCookieValue(self::COOKIE_s1);
        }
        if ($s[2]) {
            $this->setCookie(self::COOKIE_s2, $s[2]);
        } else {
            $s[2] = $this->getCookieValue(self::COOKIE_s2);
        }
        return $s;
    }

observer.php

public function execute(Observer $observer)
    {        
       $curModule = $observer->getEvent()->getControllerAction()->getRequest()->getFullActionName();
        if($curModule != 'customer_section_load'){
            echo 'In Observer';
            $this->_modelVisitor->saveVisitorData(); 
        }

    }
2
  • can you please provide code what you are trying Commented Dec 13, 2017 at 8:17
  • updated my post@ Murtuza Zabuawala
    – Mahi M
    Commented Dec 13, 2017 at 8:33

2 Answers 2

2

controller_action_predispatch event will not be called when FPC is turned ON. You have to use the event controller_front_send_response_before which will be called irrespective of the FPC running status.

0
0

in this case you can use following event

 <event name="controller_action_predispatch_customer_section_load" >

No need to check that condition

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.