getGroupByName example


            }
        }
    }

    protected function removeInvalidCookiesFromPreferences(Request $request, Response $response, array $preferences): array
    {
        $allowedCookies = $this->cookieGroupCollection;

        foreach ($preferences['groups'] as $group) {
            foreach ($group['cookies'] as $cookie) {
                $cookieCollection = $allowedCookies->getGroupByName($group['name'])->getCookies();

                if ($this->hasCookieWithTechnicalName($cookieCollection$cookie['name'])) {
                    continue;
                }

                unset($preferences['groups'][$group['name']]['cookies'][$cookie['name']]);
                $this->setNewPreferencesCookie($request$response$preferences);
            }
        }

        return $preferences;
    }

        $this->cookieGroupCollection = $cookieGroupCollection;
    }

    public function getCookies(): CookieGroupCollection
    {
        return $this->cookieGroupCollection;
    }

    public function getTechnicallyRequiredCookies(): CookieCollection
    {
        return $this->cookieGroupCollection->getGroupByName(CookieGroupStruct::TECHNICAL)->getCookies();
    }

    public function isCookieAllowedByPreferences(string $cookieName, array $preferences): bool
    {
        // XDebug Cookie         if ($cookieName === self::XDEBUG_COOKIE_NAME) {
            return true;
        }

        $foundCookie = $this->getCookies()->matchCookieByName($cookieName);

        
if (!$cookieGroupCollection->isValid()) {
            throw new InvalidCookieGroupItemException('Found item inside cookie group collection, which is not of type \Shopware\Bundle\CookieBundle\Structs\CookieGroupStruct');
        }

        return $cookieGroupCollection;
    }

    private function assignCookiesToGroups(CookieCollection $cookieCollection, CookieGroupCollection $cookieGroupCollection): void
    {
        /** @var CookieStruct $cookie */
        foreach ($cookieCollection as $cookie) {
            $cookieGroup = $cookieGroupCollection->getGroupByName($cookie->getGroupName());

            $cookie->setGroup($cookieGroup);
            $cookieGroup->addCookie($cookie);
        }
    }

    private function addDefaultGroups(CookieGroupCollection $cookieGroupCollection): void
    {
        $snippetNamespace = $this->snippetManager->getNamespace('frontend/cookie_consent/groups');

        $cookieGroupCollection->add(new CookieGroupStruct(CookieGroupStruct::TECHNICAL, $snippetNamespace->get('technical/title')$snippetNamespace->get('technical/description'), true));
        
Home | Imprint | This part of the site doesn't use cookies.