config = $config; $this->serializer = $serializer; $this->getEssentialCategoryKeys = $getEssentialCategoryKeys; $this->getCookieToCategoryMapping = $getCookieToCategoryMapping; $this->canManageCookie = $canManageCookie; $this->httpContext = $httpContext; $this->cookieConfig = $cookieConfig; $this->cookieConfigHelper = $cookieConfigHelper; $this->getDynamicNames = $getDynamicNames; $this->toRegex = $toRegex; $this->cookieProvider = $cookieProvider; $this->parentDomain = $parentDomain; } /** * Get configurations for restriction. * * @return array */ public function getRestrictionConfig(): array { return [ 'canManageCookie' => null, 'canManageCookieApiUrl' => $this->getBaseUrl() . 'rest/V1/pr_cookie/can-manage-cookie', 'canUseCookieBeforeOptIn' => $this->config->canUseCookieBeforeOptIn(), 'canBlockUnknownCookie' => $this->config->canBlockUnknownCookie(), 'consent' => [ 'isLoggedIn' => $this->isLoggedIn(), 'logUrl' => $this->isLoggedIn() ? $this->getCustomerConsentUpdateUrl() : $this->getGuestConsentUpdateUrl(), 'reloadAfterAccept' => $this->config->reloadAfterAccept(), 'reloadAfterDecline' => $this->config->reloadAfterDecline(), 'expiry' => $this->config->getConsentExpiry(), ], 'cookie' => [ 'path' => $this->cookieConfig->getCookiePath(), 'domain' => $this->cookieConfig->getCookieDomain(), 'parentDomain' => $this->parentDomain->resolve($this->cookieConfig->getCookieDomain()), ], 'cookies' => $this->getCookieData(), 'mage' => [ 'website' => (int) $this->_storeManager->getWebsite()->getId(), 'cookieName' => CookieHelper::IS_USER_ALLOWED_SAVE_COOKIE, 'lifetime' => $this->cookieConfigHelper->getCookieRestrictionLifetime(), ], 'cookieToCategoryMapping' => $this->getCookieToCategoryMapping->execute(), 'essentialCategoryKeys' => $this->getEssentialCategoryKeys->execute(), 'dynamicNamesPatterns' => $this->toRegex->execute($this->getDynamicNames->execute()), ]; } /** * Retrieve serialized config. * * @return string */ public function getSerializedRestrictionConfig(): string { return $this->serializer->serialize($this->getRestrictionConfig()); } /** * Check if customer is logged in. * * @return bool */ public function isLoggedIn(): bool { return GroupManagement::NOT_LOGGED_IN_ID !== $this->httpContext->getValue(HttpContext::CONTEXT_GROUP); } /** * Get url for customer update. * * @return string */ public function getCustomerConsentUpdateUrl(): string { return $this->getUrl('pr_cookie/consent_customer/update'); } /** * Get url for guest update. * * @return string */ public function getGuestConsentUpdateUrl(): string { return $this->getUrl('pr_cookie/consent_guest/update'); } /** * Get cookie details. * * @return array[] */ private function getCookieData(): array { $result = []; foreach ($this->cookieProvider->get() as $cookie) { $result[$cookie->getName()] = [ 'domain' => $cookie->getDomain() ]; } return $result; } }