Get Product Badges
Usage
Fetch badge configuration and match badges for a set of products by their IDs.
Use this method when you need badges for specific products outside of a search or collection flow — for example on a product detail page, a featured products section, or a custom product carousel.
For search, collection, and recommendation flows, use the withBadges: true flag on the respective method instead — it requires no extra API call.
Example
window.FastSimonSDK.getProductBadges({
productIds: ["123", "456", "789"],
callback: (result) => {
// result is a dictionary: { [productId]: Badge[] }
const badgesFor123 = result["123"];
// render badges for each product
}
});
Options
| Option | Type | Description |
|---|---|---|
| productIds | string[] (required) | Product IDs to fetch and match badges for |
| callback | (result: Record\<string, Badge[]>) => void (required) | Callback with matched badges per product ID |
Response
A dictionary mapping each product ID to its matched badges, sorted by priority and limited to the site's configured badge limit.
type Response = Record<string, Badge[]>
interface Badge {
tag: string // internal badge identifier
displayType: "text" | "image"
autoBadgeType: string // "discount" | "inventory" | "release_date" | "sales" | ""
badgeText: string // display text (text badges)
badgeStyle: {
backgroundColor?: string
textColor?: string
borderColor?: string
borderRadius?: number
size?: number
vertical?: "top" | "bottom"
horizontal?: "left" | "right"
}
autoConfig: object // discount calculation config, inventory thresholds, etc.
imageUrl: string // image URL (image badges)
priority: number
displayName?: string
}
Rendering Badges
window.FastSimonSDK.getProductBadges({
productIds: ["123"],
callback: (result) => {
const badges = result["123"] || [];
badges.forEach(badge => {
if (badge.displayType === "image") {
// render <img src={badge.imageUrl}>
} else {
// render badge.badgeText with badge.badgeStyle
// for discount badges (autoBadgeType === "discount"):
// compute text from badge.autoConfig + product price/comparePrice
}
});
}
});
Badge limits
The badges returned already respect the site's configured limits:
badgesLimit— maximum badges per product across all cornersbadgesLimitPerCorner— maximum badges per corner position (e.g. at most 2 at top-left)
Both values come from the dashboard Badges per Product and Per Corner settings and are applied automatically. No extra configuration needed in the callback.
For search and collection pages, use withBadges: true on fullTextSearch or smartCollections — badges are computed in-memory with no extra request.
getProductBadges is best suited for pages where you already know the product IDs but don't have product data yet (e.g. a PDP).