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.7 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.
| Option | Type | Default | Description |
|---|---|---|---|
availablePositions | string[] | ['top-left', 'top-right', 'bottom-left', 'bottom-right'] | Available positions selecteble in the ui |
The configured positions are also exposed on the Admin API via the getBadgePluginConfig
query, so the Admin UI can offer them as choices.
A badge holds an image asset, a position and a link to one collection. Products are never badged directly, they inherit badges from the collections they belong to:
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 all collections the product belongs to |
ProductVariant.badges | [Badge!]! | Badges from the variant's collections |
SearchResult.badges | [Badge!]! | Badges for a search result (resolved via its product's collections) |
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.