Home > widget-integration > FilterFormatHelper > isSamePrice
FilterFormatHelper.isSamePrice() method
Checks if product has same min and max prices.
Determines whether a product's price range should be collapsed to a single price by comparing both the regular prices and compare-at prices. This is useful for deciding whether to show "$10.00" versus "$10.00 - $15.00". Override this method to implement custom price comparison logic, such as tolerance-based matching.
Signature:
isSamePrice(priceMin: number | string, priceMax: number | string, compareAtPriceMin: number | string, compareAtPriceMax: number | string): boolean;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
priceMin |
number | string |
Minimum price in cents (e.g., 1000 for $10.00) |
|
priceMax |
number | string |
Maximum price in cents (e.g., 1500 for $15.00) |
|
compareAtPriceMin |
number | string |
Minimum compare-at price in cents |
|
compareAtPriceMax |
number | string |
Maximum compare-at price in cents |
Returns:
boolean
True if both min/max regular prices and compare-at prices are identical, false otherwise
Example 1
Basic usage:
const isSame = helper.isSamePrice(1000, 1000, 0, 0);
// Returns: true
Example 2
Extend to add price tolerance:
window.boostWidgetIntegration.extend('FilterFormatHelper', (FilterFormatHelper) => {
return class CustomFilterFormatHelper extends FilterFormatHelper {
isSamePrice(priceMin, priceMax, compareAtPriceMin, compareAtPriceMax) {
// Consider prices the same if within 1% tolerance
const tolerance = 0.01;
const priceDiff = Math.abs(Number(priceMax) - Number(priceMin));
const avgPrice = (Number(priceMax) + Number(priceMin)) / 2;
if (priceDiff / avgPrice <= tolerance) {
return true;
}
return super.isSamePrice(priceMin, priceMax, compareAtPriceMin, compareAtPriceMax);
}
};
});