Class FacetOptionViewModel
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a single selectable option within a facet filter in the product catalog.
public class FacetOptionViewModel : FillableViewModelBase
- Inheritance
-
FacetOptionViewModel
- Inherited Members
- Extension Methods
Remarks
A facet option is one possible filter value (e.g. "Red" within a "Color" facet).
Use Selected to reflect the current filter state, Count to show result
counts, and Value as the query-string value to apply when the customer selects the option.
Call TryGetColor(FacetOptionViewModel, out ColorViewModel?) to check whether the option value represents a colour swatch that can be rendered as a colour picker rather than a plain label.
Typical Razor template usage — render as a checkbox filter:
@foreach (var option in facet.Options)
{
<label>
<input type="checkbox" name="@facet.QueryParameter" value="@option.Value"
@(option.Selected ? "checked" : "") />
@option.Label (@option.Count)
</label>
}
Properties
Count
Gets or sets the number of products that match this facet option given the current search context. Display this alongside the label to help customers understand how many results each option yields.
public long Count { get; set; }
Property Value
Label
Gets or sets the localised display label of the facet option shown to the customer (e.g. "Red", "Size M").
public string Label { get; set; }
Property Value
Name
Gets or sets the internal name of the facet option, used as a stable identifier.
public string Name { get; set; }
Property Value
Selected
Gets or sets a value indicating whether this option is currently active (i.e. the customer has applied this filter). Use this to pre-check checkboxes or highlight the active selection in the UI.
public bool Selected { get; set; }
Property Value
Sort
Gets or sets the sort order of this option relative to other options within the same facet. Lower values appear first.
public int Sort { get; set; }
Property Value
Value
Gets or sets the query-string value submitted when the customer selects this option.
Pass this as the value of the form field named QueryParameter.
For colour facets this may be a hex code (e.g. "#FF0000") — use
TryGetColor(FacetOptionViewModel, out ColorViewModel?) to detect that case.
public string Value { get; set; }