PHPackages                             rollpix/module-discount-badge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. rollpix/module-discount-badge

ActiveMagento2-module

rollpix/module-discount-badge
=============================

Dynamic discount percentage badge for Magento 2 product prices

1.2.1(2mo ago)04MITJavaScriptPHP &gt;=8.1

Since Feb 26Pushed 2mo agoCompare

[ Source](https://github.com/ROLLPIX/M2-DiscountBadge)[ Packagist](https://packagist.org/packages/rollpix/module-discount-badge)[ RSS](/packages/rollpix-module-discount-badge/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Rollpix\_DiscountBadge
======================

[](#rollpix_discountbadge)

> **[Versión en español](README.es.md)**

**SPONSOR:** [www.rollpix.com](https://www.rollpix.com)

Dynamic discount percentage badge for Magento 2 product prices. Displays a visual badge (e.g., `21% OFF`) next to the strikethrough price wherever Magento renders prices with a discount.

Compatibility
-------------

[](#compatibility)

RequirementVersionMagento2.4.7 ~ 2.4.8PHP8.1 ~ 8.3Installation
------------

[](#installation)

### Via Composer (recommended)

[](#via-composer-recommended)

```
composer config repositories.rollpix-discount-badge vcs https://github.com/ROLLPIX/M2-DiscountBadge.git
composer require rollpix/module-discount-badge:1.0.0
bin/magento module:enable Rollpix_DiscountBadge
bin/magento setup:upgrade
bin/magento cache:flush
```

### Manual installation

[](#manual-installation)

1. Create the directory `app/code/Rollpix/DiscountBadge/`
2. Copy all repository files there
3. Run:

```
bin/magento module:enable Rollpix_DiscountBadge
bin/magento setup:upgrade
bin/magento cache:flush
```

Admin Configuration
-------------------

[](#admin-configuration)

Navigate to **Stores &gt; Configuration &gt; Rollpix &gt; Discount Badge**.

### General Settings

[](#general-settings)

FieldDescriptionDefaultEnabledEnable/disable the badge globallyNoMinimum Discount (%)Threshold to show badge (1-99)5Badge Text TemplateText template with `{discount}` placeholder`{discount}% OFF`Badge PositionWhere to place the badge (inline, over image, below price)After old priceBadge StyleVisual variant: filled, outline, pill, pill\_outline, text\_onlyFilled### PDP &amp; Listing Styles

[](#pdp--listing-styles)

Independent style settings for Product Detail Page and Product Listing contexts:

- Background Color
- Text Color
- Font Size (px)
- Border Radius (px)
- Padding
- Font Weight

### Custom CSS

[](#custom-css)

Free-form CSS textarea injected in `` for per-store overrides.

What It Does
------------

[](#what-it-does)

- Calculates discount percentage: `round(((regular_price - final_price) / regular_price) * 100)`
- Displays a badge next to the strikethrough (old) price
- Works in **all contexts**: category pages, product detail pages, widgets, search results, related/upsell/crosssell blocks
- Updates dynamically when configurable product options change the price
- Respects special prices, catalog price rules, tier prices — reads whatever Magento already calculated
- Five visual styles: Filled, Outline, Pill, Pill Outline, Text Only
- Seven position options including inline with price and over product image
- Independent styling for PDP vs. listing contexts
- Custom CSS field for per-store overrides
- Fully translatable text template per Store View

### Edge Cases

[](#edge-cases)

- `regular_price == final_price` → no badge
- `regular_price == 0` → no badge
- Discount ≤ 0% or ≥ 100% → no badge
- Discount &lt; minimum threshold → no badge

Behavior When Disabled
----------------------

[](#behavior-when-disabled)

When the module is disabled in admin:

- No JavaScript is loaded
- No CSS is injected (beyond the static base CSS which has no visual impact)
- No badge elements are rendered
- Zero performance overhead — the priceBox mixin short-circuits immediately

Technical Architecture
----------------------

[](#technical-architecture)

### File Structure

[](#file-structure)

```
M2-DiscountBadge/                          ← repo root
├── registration.php
├── composer.json
├── etc/
│   ├── module.xml
│   ├── config.xml                         # Default values
│   ├── acl.xml                            # ACL resource
│   └── adminhtml/
│       └── system.xml                     # Admin configuration
├── Model/
│   ├── Config.php                         # System config reader
│   └── Config/Source/
│       ├── BadgePosition.php              # Position options
│       ├── BadgeStyle.php                 # Style options
│       └── FontWeight.php                 # Font weight options
├── ViewModel/
│   └── DiscountBadge.php                  # Passes config to templates
├── view/frontend/
│   ├── layout/
│   │   └── default.xml                    # Injects config + CSS
│   ├── templates/
│   │   ├── badge-config.phtml             # x-magento-init JSON config
│   │   └── custom-css.phtml               # Custom CSS injection
│   ├── web/
│   │   ├── js/
│   │   │   ├── badge-renderer.js          # Shared badge logic
│   │   │   ├── discount-badge.js          # Init module (scans priceBoxes)
│   │   │   └── price-box-mixin.js         # PriceBox widget mixin
│   │   └── css/
│   │       └── discount-badge.css         # Base structural styles
│   └── requirejs-config.js                # Mixin registration
├── i18n/
│   ├── en_US.csv
│   └── es_AR.csv
├── README.md
├── README.es.md
└── LICENSE

```

### How It Works

[](#how-it-works)

1. **PHP side**: `ViewModel/DiscountBadge.php` reads admin config and outputs it as a `x-magento-init` JSON block
2. **JS init**: `discount-badge.js` stores config and scans existing priceBox widgets
3. **Mixin**: `price-box-mixin.js` hooks into `reloadPrice()` to update badges on price changes
4. **Renderer**: `badge-renderer.js` handles calculation, DOM creation, and placement

### Performance

[](#performance)

- 100% client-side — no additional server requests
- Compatible with Full Page Cache (FPC) and Varnish
- No impact on TTFB
- All blocks are cacheable
- Config does not vary per customer session

### CSS Classes

[](#css-classes)

ClassDescription`.rollpix-discount-badge`Base class`.rollpix-discount-badge--pdp`Product detail page context`.rollpix-discount-badge--listing`Listing context`.rollpix-discount-badge--inline`Inline with price`.rollpix-discount-badge--over-image`Over product image`.rollpix-discount-badge--below`Below price block`.rollpix-discount-badge--filled`Filled style`.rollpix-discount-badge--outline`Outline style`.rollpix-discount-badge--pill`Pill style`.rollpix-discount-badge--pill-outline`Pill outline style`.rollpix-discount-badge--text-only`Text only styleManual Testing Guide
--------------------

[](#manual-testing-guide)

1. Enable the module in **Stores &gt; Configuration &gt; Rollpix &gt; Discount Badge**
2. Create or find a product with a special price or catalog price rule
3. Verify the badge appears on:
    - Category listing page
    - Product detail page
    - Search results
    - Related/upsell/crosssell widgets
4. For a configurable product, change options and verify the badge updates
5. Set minimum discount to a value above the product's discount and verify the badge disappears
6. Test each position and style option
7. Test custom CSS injection
8. Disable the module and verify no badges appear

Uninstall
---------

[](#uninstall)

### Via Composer

[](#via-composer)

```
bin/magento module:disable Rollpix_DiscountBadge
composer remove rollpix/module-discount-badge
bin/magento setup:upgrade
bin/magento cache:flush
```

### Manual

[](#manual)

```
bin/magento module:disable Rollpix_DiscountBadge
rm -rf app/code/Rollpix/DiscountBadge
bin/magento setup:upgrade
bin/magento cache:flush
```

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

72d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2244b007d24a136b3d70c0daae65409d493f9ac5e3b6bd868858a907c924a4ed?d=identicon)[nmarquev](/maintainers/nmarquev)

---

Top Contributors

[![nmarquev](https://avatars.githubusercontent.com/u/20818155?v=4)](https://github.com/nmarquev "nmarquev (5 commits)")

### Embed Badge

![Health badge](/badges/rollpix-module-discount-badge/health.svg)

```
[![Health](https://phpackages.com/badges/rollpix-module-discount-badge/health.svg)](https://phpackages.com/packages/rollpix-module-discount-badge)
```

###  Alternatives

[smile/elasticsuite

Magento 2 merchandising and search engine built on ElasticSearch

8044.5M33](/packages/smile-elasticsuite)[mollie/magento2

Mollie Payment Module for Magento 2

1121.6M10](/packages/mollie-magento2)[fastly/magento2

Fastly CDN Module for Magento 2.4.x

1564.2M1](/packages/fastly-magento2)[dotdigital/dotdigital-magento2-extension

Dotdigital for Magento 2

50374.2k18](/packages/dotdigital-dotdigital-magento2-extension)[swissup/module-search-mysql-legacy

Legacy mysql search for magento 2.4

10483.0k](/packages/swissup-module-search-mysql-legacy)[lizardmedia/module-varnish-warmer

Varnish Cache Warmer Magento2 module by Lizard Media

6276.8k](/packages/lizardmedia-module-varnish-warmer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
