How to Update Properties

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

After a definition is created you can add new properties and edit or delete existing ones. You use the Catalog API to edit the catalog properties of a base catalog or a virtual catalog. For example, you can edit the category information for a catalog or start and end dates for a catalog.

To update a property

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

  2. Save the CatalogProperty object.

Example

This example demonstrates how to update an existing property. It shows how to set null and default attributes for properties.

public static void UpdateProperty(CatalogProperty property)
{
    try
    {
        // Set the required attributes on the property. 
        property.Information.CatalogProperties[0].ExportToDW = true;
        property.Information.CatalogProperties[0].DisplayName = "Test DisplayName";
        property.Information.CatalogProperties[0].DisplayInProductsList = true;

        // To set a  value of an attribute to null use the SetXXXNull() method.
        property.Information.CatalogProperties[0].SetCurrencyNull();

        // To set default values use the corresponding XXXDefaultValue method.
        // If the property is not multilingual 
        if (property.DataType == CatalogDataType.String && !property.Information.CatalogProperties[0].LanguageSensitive)
        {
                        property.Information.CatalogProperties[0].DefaultStringValue = "default";
        }
        else if (property.DataType == CatalogDataType.String && property.Information.CatalogProperties[0].LanguageSensitive)
        {
            string language = "en-US";
            // The language sensitive default value is stored in the u_defaultvalue_<language> column.
            string defaultValueColumn = string.Format("{0}_{1}", CatalogPropertiesDataSetSchema.DefaultStringValue, language);

            // Check whether the default value column exists before setting the value.
            if (property.Information.CatalogProperties.Columns.Contains(defaultValueColumn))
           {
                property.Information.CatalogProperties[0][defaultValueColumn] = "en-US default value";
            }
        }

        // Save the changes.
        property.Save();

    }
    catch (OptimisticLockException ex)
    {
         // The property was modified by another user.
         Console.WriteLine(ex.Message);
    }
}

See Also

Other Resources

How to Create a Property