Partilhar via


Extending the entites in the Catalog and Inventory Systems

Commerce Server 2007 allows you to extend the different entities in the Catalog and Inventory systems in a straightforward manner. These are the various entities that can be extended

  1. Property Definitions
  2. Catalog  Definitions
  3. Inventory Catalog
  4. Inventory Skus
  5. Product and Categories

All the above entities except 5 can be extended as follows

  1. Create a property. For eg if you want to associate a VendorId with a catalog, create a property named VendorId of datatype string.
  2. Add the property to the appropriate entity
  3. Once the entity has been added to the entity you can access its value using the indexer or the corresponding dataset. For eg. string vendorId  = (string)productCatalog["VendorId"];
  4. You can also enumerate the list of properties added to a particular entity
  5. Note that multilingual properties cannot be added to the first four entities
  6. If your site contains an inventory resource then the properties defined in the catalog system can be used to extend the Inventory Catalog and Inventry Skus entities

      The above operations can be performed from the Catalog and Inventory Schema manager. This is how you can perform the above tasks programatically.

      Assume that you want to add a VendorId property to track vendors for your product catalogs

/// <summary>

/// Extends the ProductCatalog Entity

/// </summary>

/// <param name="catalogContext"></param>

internal void ExtendCatalogEntity(CatalogContext catalogContext)

{

      // Create the property

      CatalogProperty property = catalogContext.CreateProperty("VendorId",

      CatalogDataType.String, 25);

 

      // Add the property to the ExtensibleEntityType.ProductCatalog entity

      catalogContext.AddPropertyToEntity(ExtensibleEntityType.ProductCatalog,

      "VendorId");

      // Get the properties added to the ExtensibleEntityType.ProductCatalog entity

      CatalogPropertiesDataSet extendedProperties =

      catalogContext.GetEntityProperties(ExtensibleEntityType.ProductCatalog);

      // Iterate through all the extended properties

      foreach(CatalogPropertiesDataSet.CatalogProperty extendedProperty in

               extendedProperties.CatalogProperties)

      {

            string propertyName = extendedProperty.PropertyName;

      }

      // Now assign a value to the VendorId

      ProductCatalog productCatalog = catalogContext.GetCatalog("My Catalog");

      productCatalog["VendorId"] = "My Vendor";

      // You can also use the Information property to do the same thing

      // productCatalog.Information.Catalogs[0]["VendorId"] = "My Vendor";

      // save the changes

      productCatalog.Save();

      string vendorId = null;

      // Access the value of the "VendorId" property

      // Validate that "VendorId" property has been added to the ProductCatalog

      // entity and its value is not null

      if ( productCatalog.HasProperty("VendorId")

      && !productCatalog.IsPropertyNull("VendorId"))

      {

         vendorId = (string)productCatalog["VendorId"];

         // vendorId = (string)productCatalog.Information.Catalogs[0]["VendorId"];

      }

      // Remove the property from the ProductCatalog entity

      catalogContext.RemovePropertyFromEntity(ExtensibleEntityType.ProductCatalog,

      "VendorId");

                       

}

 

In a similar manner you can extend the other entities. Use

  1. ExtensibleEntityType.PropertyDefinition for Property Definitions
  2. ExtensibleEntityType.ProductCatalog for Catalog  Definitions
  3. ExtensibleEntityType.InventoryCatalog for Inventory Catalog
  4. ExtensibleEntityType.InventorySku for Inventory Skus