name: badge-plugin title: Badge Plugin description: Vendure plugin for managing and displaying product badges via the admin UI and shop API. version: 4.0.8 tags:
A Vendure plugin for creating image badges and showing them on products in your storefront. A badge is an image asset (e.g. "New", "Sale", "Best Seller") placed at a fixed position on a product image. Badges are attached to collections, and every product in a badged collection automatically inherits that collection's badge, so you label many products at once instead of one at a time.
Badges are managed from the Admin UI and read from the Shop API, are channel-aware (each channel sees only its own badges), and expose a ready-to-use badges field on Product, ProductVariant, and SearchResult.
top-left, top-right); invalid positions are rejectedProduct, ProductVariant, and SearchResult, or query a collection's badgeVendure ^3.6.0
Or with Yarn:
Add the plugin to your Vendure configuration in vendure-config.ts:
The plugin adds a badge table (plus its channel join table) to the database, so generate
and run a migration before starting the server:
(Or generate one with your project's existing migration workflow.) Then restart the server. Badges appear under their own section in the Admin UI.
Upgrading: the badge table gets a new nullable promotionId column (a link to a
promotion). Generate and run a migration after updating. Collection and promotion badges
are now returned ordered by order, then by id. ProductVariant.badges now uses only public
collections, matching Product.badges, so a badge on a private collection no longer shows on
variants.
| Option | Type | Default | Description |
|---|---|---|---|
availablePositions | string[] | ['top-left', 'top-right', 'bottom-left', 'bottom-right'] | Available positions selecteble in the ui |
promotionProductChecks | PromotionProductCheck[] | [] | Extra checks that answer whether a product satisfies a promotion condition (see below) |
The configured positions are also exposed on the Admin API via the getBadgePluginConfig
query, so the Admin UI and the React Dashboard can offer them as choices.
A promotion badge shows on a product when every condition of the promotion is satisfied by
that product. A condition is only checked if a PromotionProductCheck is registered for its
code. The plugin ships containsProductsCheck for contains_products (registered by
default, the required quantity is ignored). A promotion with a condition that has no check
never shows its badge, and the React Dashboard lists the unchecked condition codes.
Register a check for your own condition:
A check that throws counts as no match and is logged.
The badge follows the promotion's conditions, not its actions. A promotion that limits its
discount to some products only through its action (for example products_percentage_discount
with no condition) shows the badge on every product. Give it a product condition such as
contains_products to scope the badge.
A badge holds an image asset, a position and a link to one collection or one promotion, never both. Products are never badged directly, they inherit badges from the collections they belong to or the promotions they satisfy:
badges field on a product (or search result) and
render each badge's image at its position.Because badges are channel-aware, a badge is only visible in the channel it was created in.
Badge management is exposed on the Admin API and guarded by the standard Vendure catalog permissions:
| Operation | Required permission |
|---|---|
| Query badges / plugin config | ReadCatalog |
| Create a badge | CreateCatalog |
| Update a badge | UpdateCatalog |
| Delete a badge | DeleteCatalog |
The Shop API badge queries are public, matching the rest of the Vendure shop API.
Once installed, manage badges from the dedicated Badges section in the Admin UI. From there you can:
The plugin extends the Shop API with badge queries and adds a badges resolver field to
Product, ProductVariant, and SearchResult.
| Field / Query | Returns | Description |
|---|---|---|
Product.badges | [Badge!]! | Badges inherited from the product's collections and matching active promotions |
ProductVariant.badges | [Badge!]! | Badges from the variant's collections and matching active promotions |
SearchResult.badges | [Badge!]! | Badges for a search result (its product's collections and matching active promotions) |
badges(options) | BadgeList! | Paginated list of all badges in the active channel |
getBadgeFromCollection(collectionId) | Badge | The badge assigned to a single collection, if any |
getBadgesFromCollections(collectionIds) | [Badge!]! | Badges assigned to any of the given collections |
The most common pattern is to read badges straight off a product:
Or off search results, to render badges in a product listing:
Fetch a product's badges from the Shop API and render each one at its position:
This was a version bump only for badge-plugin to align it with other projects, there were no code changes.
This was a version bump only for badge-plugin to align it with other projects, there were no code changes.
This was a version bump only for badge-plugin to align it with other projects, there were no code changes.