infrangible / m2-catalog-product-badge
Shows New, Sale and Sold Out badges on the product images of product lists and product pages, with the discount in percent if wanted.
Package info
github.com/infrangible-dev/m2-catalog-product-badge
Type:magento2-module
pkg:composer/infrangible/m2-catalog-product-badge
Requires
- php: >=8.1
- fewedev/base: ~2.4.3
- infrangible/m2-foundation: ~3.0.2
- magento/framework: ~103.0.6
- magento/module-catalog: ~104.0.6
- magento/module-catalog-widget: ~100.4.6
- magento/module-config: ~101.2.6
- magento/module-customer: ~103.0.6
- magento/module-store: ~101.1.6
Requires (Dev)
- infrangible/phpstan-magento: ~1.2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 21:28:11 UTC
README
Shows the badges New, Sale and Sold Out on the product images of product lists (categories, search results and product list widgets) and on the main image of the product page. The Sale badge can show the discount in percent, for example "-20%".
Badges
- New: while today is within "Set Product as New from" and "to" of the product (one of both is enough).
- Sale: if the final price is lower than the regular price, with special prices, catalog price rules and tier prices for one piece, for the website and customer group of the customer. The prices come from Magento's price index, so configurable products get the badge if one of their variants has a discount.
- Sold Out: if the product cannot be bought. Out of stock products are only listed if "Display Out of Stock Products" is enabled (Stores > Configuration > Catalog > Inventory > Stock Options).
Discount in percent
The Sale badge shows either its text or the discount in percent, set per store view. The percentage is only shown if all prices of the product have the same discount, for example all variants of a configurable product; otherwise the text is shown.
Look
The badges are shown in a corner of the image. Text, corner, shape, text color and background color are set per badge and store view. The shapes:
- Label (default): the text on the background color, a small rectangle.
- Ribbon: the text on a band in the background color, with swallowtail ends behind it in a darker shade of the background color, folded below the band.
- Stamp: the text in a rounded frame in the text color, on the background color, with a shadow and turned a little, like a sticker. A white background and a red text make it look like a stamp.
The badges of the same corner are shown below each other. On the product page, the thumbnails are below the image, so badges of the lower corners are shown in the upper corners there.
Themes can change the look with CSS (classes infrangible-badge, infrangible-badge-new, -sale, -sold_out and
infrangible-badge-shape-label, -ribbon, -stamp) or override the template
Infrangible_CatalogProductBadge::badges.phtml. The sizes of the shapes are LESS variables in
view/frontend/web/css/source/_module.less (@infrangible-badge-ribbon__*, @infrangible-badge-stamp__*), which a
theme can set again in its Infrangible_CatalogProductBadge/web/css/source/_extend.less, for example a bold font for
the stamp if the font of the theme has none: @infrangible-badge-stamp__font-family: 'Open Sans', sans-serif;. The
texts of the badges can be translated like other texts of the store.
Full page cache
Magento does not clean cached pages when a "new from/to" date or a special price date is reached. The module limits the cache lifetime of pages and product list widgets with badges to the next such date, for the built-in full page cache and for Varnish.
Configuration
Stores > Configuration > Infrangible Solutions > Product Badges, with a group per badge: Enable, Text, Position, Shape, Text Color, Background Color, and for Sale also Show (Text or Discount in Percent). All badges are enabled by default.
Requirements
- Magento Open Source or Adobe Commerce 2.4.6 or newer
- PHP 8.1 or newer
- The Luma theme or a theme based on it; a Hyvä version will follow as a separate module
Installation
composer require infrangible/m2-catalog-product-badge bin/magento module:enable Infrangible_CatalogProductBadge bin/magento setup:upgrade bin/magento cache:flush
In production mode, also run bin/magento setup:di:compile and bin/magento setup:static-content:deploy.
License
Infrangible Product Badges is licensed under the MIT License - see the LICENSE file for details.