You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/plugins/plugins/storefront/add-cookie-to-manager.md
+20-34Lines changed: 20 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ This guide is built upon the [Plugin base guide](../plugin-base-guide), so take
21
21
22
22
## Extend the cookie consent manager
23
23
24
-
Adding custom cookies requires you to listen to the `CookieGroupsCollectEvent` and add your custom cookies to the collection.
24
+
Adding custom cookies requires you to listen to the `CookieGroupCollectEvent` and add your custom cookies to the collection.
25
25
26
26
::: tip
27
27
It is recommended to use an event listener if you're listening to a single event. If you need to react to multiple events, an event subscriber is the better choice.
@@ -41,7 +41,7 @@ Start with creating the `services.xml` and registering your event listener.
@@ -51,7 +51,7 @@ In the next step we'll create the actual listener class.
51
51
52
52
### Creating the listener
53
53
54
-
We need to create a class called `CookieListener` with an `__invoke` method. This method will be executed once the `CookieGroupsCollectEvent` is dispatched.
54
+
We need to create a class called `CookieListener` with an `__invoke` method. This method will be executed once the `CookieGroupCollectEvent` is dispatched.
55
55
56
56
The event object that is passed to our listener method contains the cookie groups collection, which we can use to add our custom cookies.
57
57
@@ -67,47 +67,33 @@ Let's have a look at an example:
67
67
68
68
namespace PluginName\Listener;
69
69
70
-
use Shopware\Storefront\Framework\Cookie\CookieGroupsCollectEvent;
71
-
use Shopware\Core\Framework\Cookie\CookieEntry;
72
-
use Shopware\Core\Framework\Cookie\CookieGroup;
70
+
use Shopware\Core\Content\Cookie\Event\CookieGroupCollectEvent;
71
+
use Shopware\Core\Content\Cookie\Struct\CookieEntry;
72
+
use Shopware\Core\Content\Cookie\Struct\CookieGroup;
73
73
74
74
class CookieListener
75
75
{
76
-
public function __invoke(CookieGroupsCollectEvent $event): void
76
+
public function __invoke(CookieGroupCollectEvent $event): void
@@ -132,7 +118,7 @@ Cookie groups should not have the `cookie`, `value`, `expiration`, or `isRequire
132
118
133
119
## Migrating from CookieProviderInterface (Shopware 6.7.2 and earlier)
134
120
135
-
If you are upgrading from an older version, you might have used the `CookieProviderInterface` to add custom cookies. This interface is now deprecated and should be replaced with the `CookieGroupsCollectEvent`.
121
+
If you are upgrading from an older version, you might have used the `CookieProviderInterface` to add custom cookies. This interface is now deprecated and should be replaced with the `CookieGroupCollectEvent`.
136
122
137
123
For backward compatibility, you can still use the `CookieProviderInterface` to provide cookies in the old array syntax. However, it is highly recommended to use the new event-based system to provide the new object structure.
138
124
@@ -148,7 +134,7 @@ While this feature helps with GDPR compliance, shop owners are responsible for e
148
134
149
135
### How it works
150
136
151
-
1. Your plugin adds/modifies cookies via the `CookieGroupsCollectEvent`
137
+
1. Your plugin adds/modifies cookies via the `CookieGroupCollectEvent`
152
138
2. Shopware calculates a hash of the entire cookie configuration
153
139
3. The hash is stored in the user's browser
154
140
4. On the next visit, if the hash differs, the consent banner appears again
0 commit comments