Class OrderPromotionRule<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>
- Namespace
- Kentico.Xperience.Admin.DigitalCommerce
- Assembly
- Kentico.Xperience.Admin.DigitalCommerce.Shared.dll
Represents an order promotion rule with built-in functionality for common promotion scenarios.
public abstract class OrderPromotionRule<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult> : OrderPromotionRuleBase<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>, IOrderPromotionRule<TPriceCalculationRequest, TPriceCalculationResult>, IPromotionRule<TPriceCalculationRequest, TPriceCalculationResult>, IPromotionRule where TPromotionRuleProperties : OrderPromotionRuleProperties, new() where TPriceCalculationRequest : IPriceCalculationRequest where TPriceCalculationResult : IPriceCalculationResult
Type Parameters
TPromotionRulePropertiesPromotion properties type. Must inherit from OrderPromotionRuleProperties to use built-in properties.
TPriceCalculationRequestPrice calculation request type.
TPriceCalculationResultPrice calculation result type.
- Inheritance
-
objectPromotionRuleBase<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>OrderPromotionRuleBase<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>OrderPromotionRule<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>
- Implements
-
IOrderPromotionRule<TPriceCalculationRequest, TPriceCalculationResult>IPromotionRule<TPriceCalculationRequest, TPriceCalculationResult>
- Inherited Members
- Extension Methods
Remarks
This class extends OrderPromotionRuleBase<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult> and provides:
- Built-in IsApplicable(IPriceCalculationData<TPriceCalculationRequest, TPriceCalculationResult>, CancellationToken) implementation that checks minimum purchase requirements (none, minimum price, or minimum quantity).
- GetDiscountAmount(decimal) method for calculating order-level discounts based on percentage or fixed amount.
- GetDiscountValueLabel() method for formatting discount values for display purposes.
Use this class when you need standard order promotion functionality. For custom promotion logic, inherit from OrderPromotionRuleBase<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult> instead.
Constructors
OrderPromotionRule()
Creates a new instance of OrderPromotionRule<TPromotionRuleProperties, TPriceCalculationRequest, TPriceCalculationResult>.
public OrderPromotionRule()
Methods
GetDiscountAmount(decimal)
Gets the discount amount based on the given lines subtotal price and discount value specified in TPromotionRuleProperties.
protected decimal GetDiscountAmount(decimal linesSubtotalAfterLineDiscounts)
Parameters
linesSubtotalAfterLineDiscountsdecimalThe sum of all line item subtotals after line item discounts have been applied.
Returns
- decimal
The discount amount to be applied to the order. For percentage discounts, returns the calculated percentage of
linesSubtotalAfterLineDiscounts. For fixed amount discounts, returns the discount value, but not exceedinglinesSubtotalAfterLineDiscounts.
Remarks
This method calculates the order-level discount based on the promotion rule's discount type and value. The discount is calculated on the order subtotal after all catalog/line item discounts have been applied.
GetDiscountValueLabel()
Gets a human-readable label representing the discount value for display purposes.
public override string GetDiscountValueLabel()
Returns
- string
A formatted string representing the discount value (e.g., "25%" for percentage discounts or "$30.00" for fixed amount discounts). Returns
nullby default if not overridden in derived classes.
Remarks
This method is typically used to populate the display label in promotion candidates, which can be shown to users in the UI. Derived classes should override this method to provide a formatted representation of the discount value based on the promotion rule properties.
IsApplicable(IPriceCalculationData<TPriceCalculationRequest, TPriceCalculationResult>, CancellationToken)
Determines whether the promotion is applicable for the specified order based on minimum purchase requirements.
public override Task<bool> IsApplicable(IPriceCalculationData<TPriceCalculationRequest, TPriceCalculationResult> calculationData, CancellationToken cancellationToken)
Parameters
calculationDataIPriceCalculationData<TPriceCalculationRequest, TPriceCalculationResult>Price calculation data containing order information.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<bool>
trueif the promotion is applicable for the order, otherwisefalse. The promotion is applicable if:- No minimum purchase requirement is set, or
- The sum of all line item subtotals (after line item discounts) meets or exceeds the minimum purchase value, or
- The total quantity of items in the order meets or exceeds the minimum quantity requirement.
Remarks
This implementation checks the minimum purchase requirements configured in the promotion rule properties. The minimum price requirement is evaluated against the sum of line item subtotals after all catalog/line item discounts have been applied.