Class CartViewModel
- Namespace
- Dynamicweb.Frontend
- Assembly
- Dynamicweb.dll
Represents the rendering context for a shopping cart when it is displayed in frontend.
public class CartViewModel : ViewModelBase
- Inheritance
-
CartViewModel
- Inherited Members
Examples
Example usage in a Razor template:
@if (Model.Cart is { IsEmpty: false } cart) {
Items: @cart.ProductsCount
Total: @cart.TotalPrice?.Formatted
}
Remarks
This view model is exposed on the PageViewModel allowing templates to render minicart components.
All price related properties are expected to be pre-calculated by upstream logic/services.
Properties are nullable when their values may not yet be determined (e.g. before pricing is calculated).
Constructors
CartViewModel()
Initializes a new instance of the CartViewModel class with default empty state.
public CartViewModel()
Remarks
The cart is initialized as empty; collections are created and numeric totals are zeroed by caller logic.
Properties
CartOrderlines
Gets or sets the collection of orderlines currently in the cart.
public IList<CartOrderlineViewModel> CartOrderlines { get; set; }
Property Value
- IList<CartOrderlineViewModel>
The list of CartOrderlineViewModel entries; never
null.
ID
Gets or sets the cart identifier.
public string? ID { get; set; }
Property Value
- string
The unique cart identifier.
IsEmpty
Gets or sets whether the cart currently contains no orderlines.
public bool IsEmpty { get; set; }
Property Value
- bool
trueif the cart has no orderlines; otherwisefalse.
Remarks
Carts can be configured to allow zero orderlines - in those scenarios a cart can be created but contain no orderlines
OrderlinesCount
Gets or sets the number of orderlines in the cart.
public int OrderlinesCount { get; set; }
Property Value
- int
The total number of orderlines.
Remarks
An orderline can be products, discounts, giftcards and any other orderline type
PaymentFee
Gets or sets the payment fee applied for the chosen payment method.
public PriceViewModel? PaymentFee { get; set; }
Property Value
- PriceViewModel
The payment fee amount.
PaymentMethod
Gets or sets the selected payment method name or identifier.
public string? PaymentMethod { get; set; }
Property Value
- string
The payment method;
nullif not yet selected.
ProductsCount
Gets or sets the number of distinct products (unique product IDs) in the cart.
public int ProductsCount { get; set; }
Property Value
- int
The count of distinct products.
- See Also
ShippingFee
Gets or sets the shipping fee associated with the selected shipping method.
public PriceViewModel? ShippingFee { get; set; }
Property Value
- PriceViewModel
The shipping fee amount.
ShippingMethod
Gets or sets the selected shipping method name or identifier.
public string? ShippingMethod { get; set; }
Property Value
- string
The shipping method;
nullif not yet selected.
TotalDiscount
Gets or sets the aggregated discount applied to the cart (product + order discounts).
public PriceViewModel? TotalDiscount { get; set; }
Property Value
- PriceViewModel
The total discount amount (may be zero).
TotalPrice
Gets or sets the total cart price including products, discounts, fees and taxes as applicable.
public PriceViewModel? TotalPrice { get; set; }
Property Value
- PriceViewModel
The final total price.
TotalPriceWithoutDiscounts
Gets or sets the total price before any discounts are applied.
public PriceViewModel? TotalPriceWithoutDiscounts { get; set; }
Property Value
- PriceViewModel
The price prior to discounts.
TotalPriceWithoutDiscountsFeesAndTaxes
Gets or sets the total price excluding discounts, fees and taxes (raw sum of product line prices).
public PriceViewModel? TotalPriceWithoutDiscountsFeesAndTaxes { get; set; }
Property Value
- PriceViewModel
The raw product total before adjustments.
TotalPriceWithoutFees
Gets or sets the total price excluding fees (e.g. payment, shipping), but including discounts.
public PriceViewModel? TotalPriceWithoutFees { get; set; }
Property Value
- PriceViewModel
The price without additional fees.
TotalPriceWithoutOrderDiscountsAndFeesAndTaxes
Gets or sets the subtotal of all products after product-level discounts, excluding order discounts, fees and taxes.
public PriceViewModel? TotalPriceWithoutOrderDiscountsAndFeesAndTaxes { get; set; }
Property Value
- PriceViewModel
The discounted product subtotal without order-level adjustments.
TotalProductsCount
Gets or sets the total quantity of products across all orderlines (sum of quantities).
public double TotalProductsCount { get; set; }
Property Value
- double
The aggregated product quantity.
- See Also