Versuche aktuell in SW6 ein eigenes Cookie zu definieren, der gewünschte Effekt stellt sich leider nicht. Oder sagen wir mal so, ich sehe mein Cookie im Cookie-Manager nicht. Müsste doch aber zu sehen sein.
Hier mal mein bisheriger Versuch an der SW6 Dokumentation (Add cookie to manager) orientiert:
MeinPlugin\src\Resources\config\service.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="MeinPlugin\Service\CustomCookieProvider"
decorates="Shopware\Storefront\Framework\Cookie\CookieProviderInterface">
<argument type="service" id="MeinPlugin\Service\CustomCookieProvider.inner" />
</service>
</services>
</container>
MeinPlugin\src\Service\CustomCookieProvider.php
<?php declare(strict_types=1);
namespace MeinPlugin\Service;
use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;
class CustomCookieProvider implements CookieProviderInterface {
private CookieProviderInterface $originalService;
public function __construct(CookieProviderInterface $service)
{
$this->originalService = $service;
}
private const singleCookie = [
'snippet_name' => 'cookie.name',
'snippet_description' => 'cookie.description ',
'cookie' => 'cookie-key',
'value' => 'cookie value',
'expiration' => '30'
];
// cookies can also be provided as a group
private const cookieGroup = [
'snippet_name' => 'cookie.group_name',
'snippet_description' => 'cookie.group_description ',
'entries' => [
[
'snippet_name' => 'cookie.first_child_name',
'cookie' => 'cookie-key-1',
'value'=> 'cookie value',
'expiration' => '30'
],
[
'snippet_name' => 'cookie.second_child_name',
'cookie' => 'cookie-key-2',
'value'=> 'cookie value',
'expiration' => '60'
]
],
];
public function getCookieGroups(): array
{
return array_merge(
$this->originalService->getCookieGroups(),
[
self::cookieGroup,
self::singleCookie
]
);
}
}