Adding product definitions to Commerce Server is easy through the business tools. You can then add products that fit the product definitions. For example, if you create a product definition for a pair of jeans, then the product will have properties such as waist size, color and length. However, you would not want a wardrobe to have the same properties. You would create different definitions for each type of product and then match the product to the definition.
If you need to get the defintions out of CS, you can use the method
cContext.GetDefinitions()
This method is called on the Catalog Context and returns a typed dataset of product defintion attributes.
By using this method you can iterate through your product defintion attributes so you know what the attributes are called.
I am building an administration area where clients will be able to choose a category to load their products and choose the correct defintion automatically based upon the category. This means that HQ can define the catalog and category structure of Commerce Server, decide what products can go into each category, and workers can add products to only certain categories and catalogs and can be restricted by other business logic through a custom website.
This makes managing the site for large organisations much easier and more secure.
I have created a .NET user control that changes what .NET form control the user uses based upon the data type of the Product defintion property. For example a date time data type can display the calendar control, a text data type can display a text box etc.
This allows me to show the correct fields for data entry for each product and product defintion.
Unfortunately, the information returned in the dataset using the above method does not include the datatype of the properties. This means it is impossible to determine which type of control to display for each different data type.
I have therefore created a Data Access Layer that gets the information directly from the _productCatalog database.
I create the following stored proc:
--------------------
CREATE PROCEDURE [dbo].[getPropertyDefinitionsForSpecificProductDefinition]
@definitionName nvarchar(128)
AS
BEGIN
select
ca.PropertyName,ca.DataType,ca.DisplayOnSite,ca.DisplayName,cdp.DefinitionId,cdp.PropertyOrder
from
CatalogAttributes ca
join
CatalogDefinitionProperties cdp
on
ca.PropertyName = cdp.PropertyName
join
catalogDefinitions cd
on
cd.DefinitionId = cdp.DefinitionId
where
cd.DefinitionName = @definitionName
------------------------
You can then retrieve the information you need from this and load the correct controls.
--
I have linked a specific product definition to a category by a custom property in the category defintion. I only need to be able to define one product defintion per category so this works very well.
The user chooses the category of product, the product defintion is loaded by using its name.
The name is obtained from the custom property of the category the user has chosen.
I then iterate through the dataset returned from this stored procedure and display the appropriate control.