Home > widget-integration > FilterFormatHelper > isPriceAlreadyTransformed

FilterFormatHelper.isPriceAlreadyTransformed() method

Checks if price transformation has already been applied to element.

Prevents duplicate price formatting by checking for a data attribute flag on the DOM element. This is crucial for avoiding multiple transformations when price elements are re-rendered. Override this method to implement custom transformation tracking logic or use different attribute naming conventions.

Signature:

isPriceAlreadyTransformed(element: Element | null, dataAttribute?: string): boolean;

Parameters

Parameter

Type

Description

element

Element | null

DOM element to check for transformation flag

dataAttribute

string

(Optional) Data attribute name to check (without 'data-' prefix). Defaults to 'productPrice'.

Returns:

boolean

True if element has data attribute set to 'true', indicating prior transformation, false otherwise

Example 1

Basic usage:

if (!helper.isPriceAlreadyTransformed(element)) {
  // Apply price transformation
  element.setAttribute('data-productPrice', 'true');
}

Example 2

Extend to use custom tracking mechanism:

window.boostWidgetIntegration.extend('FilterFormatHelper', (FilterFormatHelper) => {
  return class CustomFilterFormatHelper extends FilterFormatHelper {
    isPriceAlreadyTransformed(element, dataAttribute = 'productPrice') {
      // Also check for CSS class as backup indicator
      if (element?.classList.contains('price-transformed')) {
        return true;
      }
      return super.isPriceAlreadyTransformed(element, dataAttribute);
    }
  };
});