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 |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
| |||
|
| |||
|
|
Record<string, RecommendationWidget> | ||
|
|
ModuleRefImpl | ||
|
| |||
|
| |||
|
| |||
|
|
Record<string, RecommendationWidget> |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Adds bundle to Shopify cart. Extension point for custom cart logic. | ||
|
Updates bundle state when variant is added. Extension point for custom add logic. | ||
|
|
Calculates which tier is currently achieved based on total quantity. Override for custom tier calculation logic. | |
|
|
Calculates discount percentage for current tier. Extension point for custom discount calculation. | |
|
|
Calculates items needed to reach next tier. | |
|
|
Calculates progress percentage to next tier. Override to customize progress calculation. | |
|
Creates TierDiscountModel from properties | ||
|
|
Enriches model with computed UI properties. Extension point for adding custom computed properties. | |
|
Fetches bundle data from API | ||
|
|
Filters products based on shop-specific criteria. Common customization point for shops. | |
|
Gets cart items from bundle model | ||
|
Gets template for widget | ||
|
Fetches and prepares tier discount model for rendering. | ||
|
|
Hook called after bundle successfully added to cart. Override for custom post-add logic like analytics or UI updates. | |
|
|
Extension point for shop-specific validation logic. Override to add custom validation rules. | |
|
|
Processes bundle data from API response | |
|
|
Recalculates bundle totals and tier achievements. Override to customize calculation logic. | |
|
Removes variant from bundle. | ||
|
|
Transforms raw bundle data to TierDiscountModelProperties | |
|
Updates bundle state when variant quantity changes. | ||
|
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 |