Jaa


How to Rank Enumerated Values of a Property

You can use ranking to control how items are displayed on your Web site. You can rank the enumeration values for an enumeration property. For example, if you have a product in several sizes, you can rank these property values to control the order in which the sizes are displayed. If you have the same rank for more than one value, they are displayed alphabetically.

To rank an enumerated value of a property

  1. Use one of the AddEnumerationPropertyValue methods of the CatalogEnumerationProperty object to create a property with a rank.

  2. Save the CatalogEnumerationProperty object.

To change the rank of an enumerated property value

  1. Use the Information property of the CatalogProperty object to update the property with the new value.

  2. Save the CatalogProperty object.

To remove an enumerated property value

  1. Use one of the RemoveEnumerationPropertyValue methods of the CatalogEnumerationProperty object to remove a property and its rank.

  2. Save the CatalogEnumerationProperty object.

Example

This example creates a new enumerated property. It adds the values Small, Medium, Large, and Extra Large and creates a rank for each of the values. It then saves the property.

public static void CatalogEnumerationProperty CreateEnumerationProperty(string propertyName)
{
    CatalogEnumerationProperty property = null;
    try
    {
        // Create an enumeration property.
        property = (CatalogEnumerationProperty)catalogContext.CreateProperty(propertyName, CatalogDataType.Enumeration, 0);
        // Add values for the enumeration property and 
        // assign a rank to each of the enumeration values.
        int rank = 0;
        property.AddEnumerationPropertyValue("Small", rank);
        property.AddEnumerationPropertyValue("Medium", ++rank);
        property.AddEnumerationPropertyValue("Large", ++rank);
        property.AddEnumerationPropertyValue("Extra Large", ++rank);

        // Save the changes to the catalog system.
        property.Save();

        // Access the enumeration values.
        foreach (CatalogEnumerationPropertyValuesDataSet.EnumerationPropertyValue enumValue in property.EnumerationValues.EnumerationPropertyValues)
        {
            Console.WriteLine(enumValue.PropertyName);
            Console.WriteLine(enumValue.PropertyValue);
            Console.WriteLine(enumValue.Rank);
        }
        
        // Remove an enumeration value.
        property.RemoveEnumerationPropertyValue("Small");

        // Save the changes to the catalog system.
        property.Save();

    }
    catch (EntityAlreadyExistsException ex)
    {
        string message = string.Format("The property {0} already exists", ex.EntityName);
        Console.WriteLine(message);
    }
    return property;
}

See Also

Other Resources

How to Create a Property