Customizing the Shopware GARAN Label Position in Shopping Experiences
Customizing the Shopware GARAN Label Position in Shopping Experiences
Merchants often seek greater control over their storefronts, especially when it comes to legally mandated elements like the GARAN (guarantee) label. This Shopware forum topic delves into a common challenge: repositioning the GARAN label from its default location on product detail pages, particularly when these pages are built using Shopware’s flexible Shopping Experiences (Erlebniswelten).
The Challenge: Repositioning the GARAN Label
The discussion began with a user, cbm, who needed to move the GARAN label from its standard placement directly beneath the "Add to cart" button. This default position, while functional, might not always align with a store's specific design or user experience goals. The core questions were twofold: first, whether the default position was a legal requirement, and second, how to achieve custom placement using Twig code in Shopware 6.6.
Initial responses in the thread showed some confusion regarding the GARAN label's functionality in Shopware 6.6, with some suggesting complex custom coding. However, a detailed and authoritative answer from Julian_Braeucker clarified the situation and provided a robust solution.
Legal Clarification on GARAN Label Placement
Julian_Braeucker addressed the legal aspect directly: "Eine feste Stelle schreibt die EU-Verordnung nach allem, was ich dazu gelesen habe, nicht vor." (Based on what I've read, the EU regulation does not prescribe a fixed position.) While it's essential for the guarantee label to be on the product page and not just in the checkout, its exact placement is flexible. The default position chosen by Shopware is merely a standard, not a legal mandate. However, for definitive legal advice, consulting an attorney is always recommended.
Step-by-Step Twig Customization Guide
Julian_Braeucker confirmed that the necessary Twig code for the GARAN label is indeed available in Shopware 6.6, specifically since version 6.6.10.24. The label resides within the buy_widget_garan_label block in storefront/component/buy-widget/buy-widget.html.twig, which is integrated into Shopping Experiences. Here’s how to move it:
Step 1: Remove the GARAN Label from its Standard Position
To prevent the label from appearing in its default spot, you need to override the relevant Twig block in your custom theme. Create a file at Resources/views/storefront/component/buy-widget/buy-widget.html.twig within your theme and add the following code:
{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget.html.twig' %}
{% block buy_widget_garan_label %}{% endblock %}
This effectively empties the block, removing the label from its original placement.
Step 2: Copy the Original GARAN Label Block
Next, you’ll need the original content of the GARAN label block. Locate the file at vendor/shopware/storefront/Resources/views/storefront/component/buy-widget/buy-widget.html.twig. Copy everything from {% block buy_widget_garan_label %} to its corresponding {% endblock %}. Then, paste this copied content into a new, custom Twig file within your theme, for example, Resources/views/storefront/component/product/garan-label.html.twig.
Step 3: Embed the GARAN Label in Your Desired Location
Now that you have the GARAN label content in a separate file, you can include it anywhere within your Shopping Experience product page templates. Since product pages in Shopping Experiences make the product data available as page.product, you can use this to conditionally display the label. For instance, to place it under an image gallery (by extending element/cms-element-image-gallery.html.twig):
{% if page.product ?? false %}
{% sw_include '@Storefront/storefront/component/product/garan-label.html.twig' with { product: page.product } %}
{% endif %}
The {% if page.product ?? false %} condition is crucial, as elements like an image gallery might also appear on pages where no product context is available.
An important note from Julian_Braeucker: the GARAN label's expand/collapse functionality and its styling are independent of the Buy-Box, meaning they will continue to work correctly regardless of where you place the label. For truly free positioning as a standard CMS element, creating a dedicated custom CMS element would be necessary, though this involves more development effort.
Crucial Update Warning: When implementing such customizations, always remember that you are copying Shopware's original code. Shopware has made several changes to the GARAN label block in recent 6.6 releases. Your copied block will not automatically receive these updates. Therefore, it is essential to periodically check the original block in new Shopware versions and manually apply any relevant changes to your custom file.
Conclusion
This forum topic provides an excellent example of how to tackle specific frontend customization challenges in Shopware 6. The detailed solution for repositioning the GARAN label offers significant actionable value for developers and merchants looking to enhance their product page layouts while maintaining legal compliance. It highlights the power of Shopware's theme inheritance and Twig templating for flexible storefront design.