Shopware 6

Unlock Merchandising Power: Custom Product Badges in Shopware 6 for Clearance, New Arrivals & Beyond

In the competitive world of e-commerce, capturing customer attention is paramount. Visual cues like product badges are powerful tools for highlighting key product attributes, driving urgency, and guiding purchasing decisions. Whether it's a 'New Arrival,' a 'Top Seller,' or a highly anticipated 'Clearance Sale' item, a well-placed badge can significantly impact conversion rates. At Migrate My Store, we understand the importance of sophisticated merchandising in Shopware 6, and today, we're diving into how you can implement custom product badges, specifically focusing on the often-requested 'Abverkauf' (clearance sale) badge.

Shopware 6 Twig code for custom product badge implementation in badges.html.twig
Shopware 6 Twig code for custom product badge implementation in badges.html.twig

Why Product Badges Are Essential for Your Shopware Store

Product badges serve multiple critical functions in an online store:

  • Instant Information: They provide immediate visual information about a product's status or unique selling proposition without the customer needing to click through to the product page.
  • Urgency & Scarcity: Badges like 'Clearance' or 'Limited Stock' create a sense of urgency, encouraging quicker purchase decisions.
  • Improved Discoverability: They help customers quickly identify products that match their current interests, such as new items or discounted goods.
  • Enhanced Merchandising: They allow you to strategically promote specific product categories or campaigns, aligning with your marketing goals.
  • Increased Conversions: By drawing attention to desirable features or offers, badges can directly contribute to higher click-through rates and sales.

The Shopware 6 Challenge: A Community-Driven Solution

Interestingly, despite the clear demand, a direct feature request for a 'badge for clearance sale' was previously rejected by Shopware's feedback platform. This often leaves merchants wondering how to achieve such a crucial merchandising element. Fortunately, the robust and flexible architecture of Shopware 6, coupled with its active developer community, provides a clear path forward: custom theme development.

As highlighted in a recent Shopware forum discussion, experts like MrAle and aggrosoft quickly pointed towards theme customization using Twig as the most efficient solution. This approach leverages Shopware's template inheritance system, allowing you to extend existing templates without directly modifying core files, ensuring update compatibility.

Implementing Your Custom 'Clearance' Badge: A Step-by-Step Guide

The core of adding a custom badge lies in modifying the relevant Twig template file within your Shopware 6 theme. The primary file responsible for displaying product badges on product cards (e.g., in listings, carousels) is storefront/component/product/card/badges.html.twig.

1. Create a Custom Theme or Child Theme

Before making any modifications, ensure you are working within a custom theme or a child theme. Directly editing the default Shopware theme is highly discouraged, as your changes will be overwritten during updates.

2. Extend the Badges Template

You'll need to create a file in your custom theme that extends the original badges.html.twig. The path would typically look something like /src/Storefront/Resources/views/storefront/component/product/card/badges.html.twig.

Inside this file, you can override or extend specific blocks. For adding a new badge, we'll hook into an existing block, such as component_product_badges_new, to ensure our badge appears alongside others.

{% sw_extends '@Storefront/storefront/component/product/card/badges.html.twig' %}

{% block component_product_badges_new %}
    {{ parent() }}

    {# Our custom 'Clearance' badge logic #}
    {% if product.customFields.custom_clearance_sale %}
        {{ 'listing.boxLabelClearance'|trans|sw_sanitize }}
    {% endif %}
{% endblock %}

Let's break down this code:

  • {% sw_extends '@Storefront/storefront/component/product/card/badges.html.twig' %}: This line tells Shopware that our template extends the original badges template.
  • {% block component_product_badges_new %} ... {% endblock %}: We are extending the block where the 'New' badge is rendered. You could choose another block or create a new one if preferred.
  • {{ parent() }}: This is crucial! It ensures that any existing content within the original component_product_badges_new block (like the 'New' badge itself) is still rendered. Without it, you'd replace the original content instead of adding to it.
  • ...: This is the HTML structure for your badge. We've used bg-danger for a red background (Bootstrap class) and badge-clearance for custom styling.
  • {{ 'listing.boxLabelClearance'|trans|sw_sanitize }}: This handles the badge text. |trans ensures it's translatable (you'll need to add this snippet to your theme's translation files, e.g., en-GB.json, de-DE.json). |sw_sanitize prevents XSS attacks.

3. Defining the 'Clearance' Condition: The Power of Custom Fields

The most critical part of a 'Clearance' badge is how you define which products are actually on clearance. While the forum example used product.available, this typically indicates general stock availability, not a specific clearance status. For a true 'Abverkauf' badge, we recommend using Shopware's Custom Fields:

  1. Create a Custom Field Set: In your Shopware 6 admin, navigate to Settings > System > Custom Fields. Create a new custom field set and assign it to 'Products'.

  2. Add a Custom Field: Within this set, add a new field. Choose 'Checkbox' as the type. Give it a technical name like custom_clearance_sale and a user-friendly label like 'Is Clearance Sale Item?'.

  3. Assign to Products: Now, when you edit a product, you'll see this checkbox. Simply tick it for any product you want to mark as 'Clearance'.

  4. Access in Twig: In your Twig template, you can then access this custom field using product.customFields.custom_clearance_sale. This provides a clean, admin-manageable way to control your badges.

Alternatively, for more complex scenarios, you could use product streams to group clearance items, but custom fields offer direct control at the product level for badge display.

A developer's screen displaying Shopware 6 Twig template code, specifically highlighting the badges.html.twig file with an added custom block for a 'Clearance' badge, demonstrating the template extension process.
A developer's screen displaying Shopware 6 Twig template code, specifically highlighting the badges.html.twig file with an added custom block for a 'Clearance' badge, demonstrating the template extension process.

4. Styling Your Badge with CSS

Once the badge is rendered, you'll want to style it to match your brand. In your theme's SCSS/CSS files, you can target the .badge-clearance class:

.badge-clearance {
    background-color: #dc3545; /* Bootstrap 'danger' red */
    color: #fff;
    padding: 0.25em 0.5em;
    border-radius: 0.25rem;
    font-size: 0.75em;
    font-weight: bold;
    margin-left: 0.5rem; /* Space from other badges */
}

Remember to compile your theme's assets after making CSS changes.

Best Practices and Considerations

  • Don't Overdo It: While powerful, too many badges can clutter your product cards and overwhelm customers. Use them strategically.
  • Mobile Responsiveness: Ensure your badges look good and are readable on all devices.
  • Performance: The Twig modifications are minimal and should not significantly impact performance.
  • Maintainability: Always use a child theme for customizations to simplify future Shopware updates.
  • Translations: Provide translations for your badge text to cater to all your shop's languages.

Migrate My Store: Ensuring Your Customizations Thrive

Implementing custom features like product badges is a testament to the flexibility of Shopware 6. When considering a migration to or within Shopware, it's crucial that these valuable customizations are not lost but seamlessly integrated into your new platform. At Migrate My Store, our expertise in Shopware migrations ensures that every bespoke element, from custom badges to complex integrations, is meticulously transferred and optimized, preserving your unique merchandising strategies and enhancing your store's functionality.

Conclusion

Custom product badges are a simple yet incredibly effective way to elevate your Shopware 6 store's merchandising. By leveraging Shopware's flexible templating system and custom fields, you can easily implement 'Clearance Sale' badges and beyond, providing clear visual cues that drive customer engagement and boost sales. Embrace these development integrations to give your products the spotlight they deserve and empower your e-commerce success.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools