Skip to content

Commit

Permalink
Merge pull request #1436 from rbayet/feat-tracker-helper-get-visitor-…
Browse files Browse the repository at this point in the history
…and-session-ids

Feat tracker helper get visitor and session ids
  • Loading branch information
romainruaud authored Jun 21, 2019
2 parents 343035a + 9e56837 commit e82e5fa
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/module-elasticsuite-tracker/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,29 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
private $sessionManager;

/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/
private $cookieManager;

/**
* PHP Constructor
*
* @param \Magento\Framework\App\Helper\Context $context The current context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager The Store Manager
* @param \Magento\Framework\Session\SessionManagerInterface $sessionManager Session Manager
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager Cookie manager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Session\SessionManagerInterface $sessionManager
\Magento\Framework\Session\SessionManagerInterface $sessionManager,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->storeManager = $storeManager;
$this->sessionManager = $sessionManager;
$this->cookieManager = $cookieManager;
parent::__construct($context);
}

Expand Down Expand Up @@ -168,4 +176,40 @@ public function getRetentionDelay()
{
return (int) $this->scopeConfig->getValue(self::CONFIG_RETENTION_DELAY_XPATH);
}

/**
* Return the current tracker visitor id
*
* @return null|string
*/
public function getCurrentVisitorId()
{
$visitorId = null;

$cookieConfig = $this->getCookieConfig();
if (array_key_exists('visitor_cookie_name', $cookieConfig)) {
$visitorCookieName = $cookieConfig['visitor_cookie_name'];
$visitorId = $this->cookieManager->getCookie($visitorCookieName);
}

return $visitorId;
}

/**
* Return the current tracker session id
*
* @return null|string
*/
public function getCurrentSessionId()
{
$visitorId = null;

$cookieConfig = $this->getCookieConfig();
if (array_key_exists('visit_cookie_name', $cookieConfig)) {
$sessionCookieName = $cookieConfig['visit_cookie_name'];
$visitorId = $this->cookieManager->getCookie($sessionCookieName);
}

return $visitorId;
}
}

0 comments on commit e82e5fa

Please sign in to comment.