Help your Sylius store comply with the GDPR: anonymize customers and export their personal data from the admin panel or the command line.
- Anonymize a customer from the GDPR section of the admin customer page.
- Export customer data as a JSON file from the same section.
- Bulk anonymization from the GDPR admin page: customers who have not logged in since a given date, or customers without any order.
- Anonymize any entity from the command line.
- Configurable anonymization (YAML mappings or PHP attribute) and export (Symfony Serializer groups).
- Extensible: events around anonymization and export, custom bulk actions.
| Version | |
|---|---|
| PHP | ^8.3 (8.4+ for Symfony 8) |
| Sylius | ^2.2.13 |
| Symfony | ^6.4 | ^7.4 | ^8.0 |
-
Require the plugin:
composer require synolia/sylius-gdpr-plugin
-
Register the bundle in
config/bundles.phpif Symfony Flex did not do it:Synolia\SyliusGDPRPlugin\SynoliaSyliusGDPRPlugin::class => ['all' => true],
-
Import the configuration in
config/packages/synolia_sylius_gdpr.yaml:imports: - { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/app/config.yaml" }
-
Import the admin routes in
config/routes/synolia_sylius_gdpr.yaml:synolia_gdpr: resource: "@SynoliaSyliusGDPRPlugin/Resources/config/routes.yaml" prefix: '/%sylius_admin.path_name%'
-
Clear the cache:
php bin/console cache:clear
The plugin ships with mappings for the Sylius Customer, ShopUser, Address, Order and Payment entities:
see src/Resources/config/mappings.
Add your own mapping directories, and optionally disable the default mappings:
synolia_sylius_gdpr:
disable_default_mappings: false # default: false
anonymization:
mappings:
paths:
- '%kernel.project_dir%/config/gdpr/mappings'Each file maps the properties of a class:
Sylius\Component\Core\Model\Customer:
properties:
firstName:
faker: firstName
prefix: 'anonymized-'
lastName:
value: 'Fake lastName'
phoneNumber: ~ # set to null
defaultAddress: ~ # related entity: anonymized with its own mapping
orders: ~ # collection: each item is anonymized with its own mappingYou can also configure a property with the #[Anonymize] attribute, which accepts the same options:
use Synolia\SyliusGDPRPlugin\Attribute\Anonymize;
class Customer extends BaseCustomer
{
#[Anonymize(['faker' => 'email', 'unique' => true, 'prefix' => 'anonymized-'])]
protected $email;
}| Option | Description |
|---|---|
faker |
Faker formatter used to generate the value, e.g. email, lastName |
args |
Arguments passed to the Faker formatter, e.g. [20] |
unique |
Generates a unique value (Faker unique() modifier) |
prefix |
String prepended to the generated value |
value |
Fixed value: null, a string, an int, an array or an expression |
A value starting with @= is evaluated with the Expression Language.
The object variable is the entity being anonymized:
Sylius\Component\Core\Model\Customer:
properties:
email:
value: '@="anonymized-" ~ object.getId() ~ "@example.com"'Anonymize any entity from the command line:
php bin/console synolia:gdpr:anonymize --entity='Sylius\Component\Core\Model\Customer' --id=1| Option | Description |
|---|---|
--entity/-E |
Fully qualified class name of the entity |
--id/-i |
Identifier of the entity. Without it, every entity of the class is anonymized |
--force |
Skips the confirmation question |
--reset |
Resets the Faker unique generator |
--max-retries |
Maximum number of retries to get unique values |
The export serializes the customer with the synolia:gdpr:customer_data serialization group
(Synolia\SyliusGDPRPlugin\Enum\GDPRSerializationKeyEnum::CUSTOMER_DATA).
See the default configuration in src/Resources/config/serialization.
To export more data, add this group to your own serialization mapping, for example with an attribute:
use Symfony\Component\Serializer\Attribute\Groups;
use Synolia\SyliusGDPRPlugin\Enum\GDPRSerializationKeyEnum;
class Customer extends BaseCustomer
{
#[Groups([GDPRSerializationKeyEnum::CUSTOMER_DATA])]
protected ?string $loyaltyNumber = null;
}The GDPR admin page lists bulk anonymization forms. To add yours:
-
Create a form type, and pass it to the controller with the
$formsTypeargument:services: Synolia\SyliusGDPRPlugin\Controller\AdvancedActionsController: arguments: $formsType: - App\Form\Type\AnonymizeCustomersFromCountryType tags: ['controller.service_arguments']
-
Create a processor implementing
Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\AdvancedActionsFormDataProcessorInterface. It is registered automatically thanks to autoconfiguration.getFormTypesClass()returns the form types it handles, andprocess()receives the submitted form.
See AnonymizeCustomersNotLoggedBeforeProcessor for an example.
| Event | Dispatched |
|---|---|
Synolia\SyliusGDPRPlugin\Event\BeforeAnonymize |
Before anonymizing any entity |
Synolia\SyliusGDPRPlugin\Event\AfterAnonymize |
After anonymizing any entity |
Synolia\SyliusGDPRPlugin\Event\BeforeCustomerAnonymize |
Before anonymizing a customer from the admin page |
Synolia\SyliusGDPRPlugin\Event\AfterCustomerAnonymize |
After anonymizing a customer from the admin page |
Synolia\SyliusGDPRPlugin\Event\BeforeExportCustomerData |
Before exporting the customer data |
The plugin is developed and tested with the Sylius Test Application:
make install # optionally: make install -e SYLIUS_VERSION=2.2.0 SYMFONY_VERSION=6.4
make phpunit
make serve # or: APP_ENV=test symfony server:start -dUse vendor/bin/console to run Symfony commands against the test application.
See How to contribute for more details (database configuration, versions, ...).
This plugin is released under the EUPL-1.2 license.
Developed by Synolia.
