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();
}
}