Class DiscountViewModel
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a view model for a discount applied to a product or order, used for rendering campaign and pricing information in frontend templates.
public class DiscountViewModel : FillableViewModelBase
- Inheritance
-
DiscountViewModel
- Inherited Members
Remarks
A discount can be either a fixed amount (Amount) or a percentage (Percentage) reduction. It may be tied to a marketing campaign (see CampaignName, CampaignDescription, CampaignColor, CampaignImage) and optionally restricted to a voucher code (VoucherCode).
In Razor templates, check both Amount and Percentage to determine how the discount should be displayed:
@if (discount.Percentage > 0)
{
<span>@discount.Name (-@discount.Percentage%)</span>
}
else
{
<span>@discount.Name (-@discount.Amount @discount.CurrencyCode)</span>
}
Properties
Amount
Gets the fixed monetary amount of the discount in CurrencyCode units.
Is 0 when the discount is percentage-based — check Percentage in that case.
public double Amount { get; }
Property Value
CampaignColor
Gets the campaign highlight colour as a CSS-compatible colour string (e.g. "#FF0000").
Use this to visually distinguish campaign labels or badges in the template.
May be null if no colour is defined.
public string CampaignColor { get; }
Property Value
CampaignDescription
Gets the description of the marketing campaign associated with this discount, suitable for display as promotional copy.
public string CampaignDescription { get; }
Property Value
CampaignImage
Gets the campaign image associated with this discount, suitable for use as a promotional banner or badge. May be null if no campaign image is configured.
public MediaViewModel CampaignImage { get; }
Property Value
CampaignName
Gets the name of the marketing campaign this discount belongs to (e.g. "Black Friday").
May be null if the discount is not associated with a campaign.
public string CampaignName { get; }
Property Value
CurrencyCode
Gets the ISO 4217 currency code for the Amount (e.g. "USD", "EUR").
public string CurrencyCode { get; }
Property Value
Name
Gets the name of the discount rule (e.g. "Summer Sale").
public string Name { get; }
Property Value
Percentage
Gets the percentage reduction of the discount (e.g. 10 means 10 % off).
Is 0 when the discount is a fixed amount — check Amount in that case.
public double Percentage { get; }
Property Value
ValidFrom
Gets the date from which the discount is active, or null if there is no start date restriction.
public DateTime? ValidFrom { get; }
Property Value
ValidTo
Gets the date until which the discount is active, or null if there is no end date restriction.
public DateTime? ValidTo { get; }
Property Value
VoucherCode
Gets the voucher code that must be entered to activate this discount, or null if the discount is not voucher-gated.
public string VoucherCode { get; }
Property Value
VoucherListId
Gets the ID of the voucher list this discount belongs to, or null if the discount is not voucher-based.
public int? VoucherListId { get; }
Property Value
- int?