searchCriteriaBuilder = $searchCriteriaBuilder; $this->serializer = $serializer; $this->cookieCategoryRepository = $cookieCategoryRepository; $this->integrationConfig = $integrationConfig; } /** * @return bool */ public function shouldDeclineAllCategories(): bool { return $this->integrationConfig->shouldDeclineAllCategories(); } /** * Get prepared list of allowed cookie categories * * @return array */ public function getAllowedCategories(): array { $allowedCategories = []; $categoriesToDecline = $this->integrationConfig->getCategoriesToDecline(); $categories = $this->cookieCategoryRepository ->getList($this->searchCriteriaBuilder->create()) ->getItems(); foreach ($categories as $category) { if (! $category->isEnabled()) { continue; } if (! $category->isEssential() && in_array($category->getKey(), $categoriesToDecline, true)) { continue; } $allowedCategories[] = $category->getKey(); } return $allowedCategories; } /** * Get prepared list of allowed cookie categories in JSON format * * @return string */ public function getAllowedCategoriesJson(): string { return $this->serializer->serialize( $this->getAllowedCategories() ); } /** * Get prepared list cookie categories to decline in JSON format * * @return string */ public function getCategoriesToDeclineJson() { return $this->serializer->serialize( $this->integrationConfig->getCategoriesToDecline() ); } }