Markus Michalski FAQ

Klaro Cookie Consent: Technical

Technical details of Klaro Cookie Consent for Shopware 6.7 - architecture, plugin structure, database tables, overridden template blocks and snippet namespaces.

Deutsche Version

Back to overview

Klaro Cookie Consent: Technical

This documentation always describes the latest published version.

Architecture

graph TD
    A["StorefrontRenderEvent"] --> B["StorefrontRenderSubscriber"]
    B --> C["KlaroConfigService"]
    C --> D["Load cookie services from the database"]
    C --> E["Load snippet texts via the translator"]
    C --> F["Plugin configuration via SystemConfig"]
    D --> G["Generate Klaro JS configuration"]
    E --> G
    F --> G
    G --> H["Twig template renders the configuration"]
    H --> I["Klaro JS initializes"]

The subscriber listens to the StorefrontRenderEvent and provides the template with the parameters mmdKlaroActive, mmdKlaroConfig, mmdKlaroPrimaryColor, mmdKlaroSecondaryColor, mmdKlaroDeclineColor, mmdKlaroGoogleConsentMode, mmdKlaroGoogleConsentModeWaitForUpdate and mmdKlaroShowFooterLink. The KlaroConfigService reads all settings with the ID of the current sales channel, and only services assigned to that sales channel make it into the configuration.

All texts end up in Klaro's fallback key zz. As a result, Klaro always shows the language of the shop and not the language of the browser.

Selection values (category, position, theme, storage method) and free text values (storage name, privacy URL, technical name) are checked against allowlists or character patterns before output.

Plugin structure

src/
β”œβ”€β”€ MmdKlaroCookieConsent.php            Plugin class (uninstall cleans up tables and configuration)
β”œβ”€β”€ Core/
β”‚   β”œβ”€β”€ Content/CookieService/           Entity, definition and collection of the cookie services
β”‚   β”‚   └── Aggregate/                   Translation and sales channel assignment
β”‚   └── Klaro/                           KlaroConfigService and KlaroConfigServiceInterface, builds the Klaro configuration
β”œβ”€β”€ Storefront/Subscriber/               StorefrontRenderSubscriber
β”œβ”€β”€ Migration/                           Database migrations
└── Resources/
    β”œβ”€β”€ app/administration/              Admin module mmd-klaro-service
    β”œβ”€β”€ config/                          config.xml, services.xml
    β”œβ”€β”€ public/administration/           Precompiled admin assets
    β”œβ”€β”€ public/storefront/vendor/klaro/  klaro.js and klaro.css
    β”œβ”€β”€ snippet/                         Storefront snippets (de_DE, en_GB)
    └── views/storefront/                Template overrides

Database tables

Table Content
mmd_klaro_cookie_service Cookie services with technical name, category, flags, cookie rules and position
mmd_klaro_cookie_service_translation Title and description per language
mmd_klaro_cookie_service_sales_channel Assignment of services to sales channels

The plugin ships four migrations: creating the tables, creating the default service session, removing a former callback field, and removing obsolete configuration fields for category texts (replaced by snippets).

Template blocks

The plugin extends three storefront templates via sw_extends. Another plugin or theme can extend these blocks as well:

Template Overridden block Purpose
storefront/base.html.twig base_cookie_permission Suppresses the native Shopware cookie notice when Klaro is active
storefront/base.html.twig base_body_script Outputs the Klaro configuration, the Google Consent Mode code, the anchor handler and the Klaro script
storefront/layout/footer/footer.html.twig layout_footer_service_menu_content Appends the "Cookie Settings" footer link
storefront/layout/meta.html.twig layout_head_stylesheet Includes klaro.css and the color variables

Snippet namespaces

Namespace Usage
mmd-klaro Storefront: dialog texts and category texts
mmd-klaro-service Administration: labels of the admin module

Extension points

The plugin dispatches no events of its own, registers no routes and no console commands. It only subscribes to the StorefrontRenderEvent.