Table of Contents

Class FacetOptionViewModelExtensions

Namespace
Dynamicweb.Ecommerce.ProductCatalog
Assembly
Dynamicweb.Ecommerce.dll

Provides extension methods for the FacetOptionViewModel class.

public static class FacetOptionViewModelExtensions
Inheritance
FacetOptionViewModelExtensions
Inherited Members

Methods

TryGetColor(FacetOptionViewModel, out ColorViewModel?)

Tries to get the color from the facet option if it is a hex value or if it is a variant option with a color set on it.

public static bool TryGetColor(this FacetOptionViewModel facetOption, out ColorViewModel? color)

Parameters

facetOption FacetOptionViewModel

The facet option to get the color from.

color ColorViewModel

The color view model if the color is successfully retrieved, otherwise null.

Returns

bool

True if the color is successfully retrieved, otherwise false.

Remarks

This method tries to get the color from the facet option by following these steps:

  1. If the facet option is null, it sets the color to null and returns false.
  2. If the facet option value starts with '#' and has a length of 7 or 4, it creates a new ColorViewModel with the facet option value as the Hex property and returns true.
  3. It tries to get the variant option using the facet option value. If the variant option is not null and has a non-empty color, it creates a new ColorViewModel with the variant color and returns true.
  4. If none of the above conditions are met, it sets the color to null and returns false.
To top