Home > widget-integration > TierDiscountService

TierDiscountService class

Service for managing tier discount bundle business logic.

Provides methods for: - Calculating tier achievements and discounts - Managing bundle cart state - Processing product selections - Validating bundle configurations

Technical Support teams can extend this class to customize business logic for specific shops without modifying core functionality.

Signature:

export declare class TierDiscountService 

Example

Extend to add custom tier calculation:

class CustomTierDiscountService extends TierDiscountService {
  protected calculateCurrentTier(model: TierDiscountModel): number {
    const baseTier = super.calculateCurrentTier(model);
    // Add VIP bonus tier
    if (this.isVIPCustomer()) {
      return Math.min(baseTier + 1, model.properties.discounts.length);
    }
    return baseTier;
  }
}

Constructors

Constructor

Modifiers

Description

(constructor)(moduleRef, appService, platformLoader, templateAPI, cartAPI, tierDiscountAPI)

Constructs a new instance of the TierDiscountService class

Properties

Property

Modifiers

Type

Description

appService

protected

AppService

cartAPI

protected

CartAPI

defaultSettings

readonly

Record<string, RecommendationWidget>

moduleRef

protected

ModuleRefImpl

platformLoader

protected

PlatformLoader

templateAPI

protected

TemplateAPI

tierDiscountAPI

protected

TierDiscountAPI

widgets

readonly

Record<string, RecommendationWidget>

Methods

Method

Modifiers

Description

addBundleToCart(model)

Adds bundle to Shopify cart. Extension point for custom cart logic.

addVariantToBundle(model, variantData)

Updates bundle state when variant is added. Extension point for custom add logic.

calculateCurrentTier(properties)

protected

Calculates which tier is currently achieved based on total quantity. Override for custom tier calculation logic.

calculateDiscountPercent(properties, tierIndex)

protected

Calculates discount percentage for current tier. Extension point for custom discount calculation.

calculateItemsToNextTier(properties)

protected

Calculates items needed to reach next tier.

calculateProgressPercent(properties)

protected

Calculates progress percentage to next tier. Override to customize progress calculation.

createModel(properties)

Creates TierDiscountModel from properties

enrichModelWithComputedProperties(properties)

protected

Enriches model with computed UI properties. Extension point for adding custom computed properties.

fetchBundle(widgetId, params)

Fetches bundle data from API

filterBundleProducts(products, config)

protected

Filters products based on shop-specific criteria. Common customization point for shops.

getBundleCartItems(model)

Gets cart items from bundle model

getBundleData(widgetId)

getTemplate(widgetId, templateKey)

Gets template for widget

getTierDiscountModel(widgetId, params)

Fetches and prepares tier discount model for rendering.

getWidgetSettings(widgetId)

isValidBundle(widgetId)

onBundleAddedToCart(model)

protected

Hook called after bundle successfully added to cart. Override for custom post-add logic like analytics or UI updates.

performShopValidation(widgetId)

protected

Extension point for shop-specific validation logic. Override to add custom validation rules.

processBundleData(bundleData, widgetId)

protected

Processes bundle data from API response

recalculateTotals(model)

protected

Recalculates bundle totals and tier achievements. Override to customize calculation logic.

removeVariantFromBundle(model, variantId)

Removes variant from bundle.

setBundleData(widgetId, data)

transformBundleData(bundleData, widgetId)

protected

Transforms raw bundle data to TierDiscountModelProperties

updateVariantQuantity(model, variantId, quantity)

Updates bundle state when variant quantity changes.

validateTierDiscountWidget(widgetId)

Validates whether a tier discount bundle should be rendered.

Checks: - Widget configuration exists - Current page context matches widget settings - Bundle has valid products - Bundle has valid discount tiers