CreateProduct Method (String, String)
Creates a root product in the catalog with the specified Product definition and product identifier. The product is created with a List Price =0.
Namespace: Microsoft.CommerceServer.Catalog
Assembly: Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)
Syntax
'Declaration
Public Function CreateProduct ( _
definitionName As String, _
productId As String _
) As Product
'Usage
Dim instance As BaseCatalog
Dim definitionName As String
Dim productId As String
Dim returnValue As Product
returnValue = instance.CreateProduct(definitionName, _
productId)
public Product CreateProduct(
string definitionName,
string productId
)
public:
Product^ CreateProduct(
String^ definitionName,
String^ productId
)
public function CreateProduct(
definitionName : String,
productId : String
) : Product
Parameters
- definitionName
Type: System..::.String
The product definition used to create the product.
- productId
Type: System..::.String
The product identifier.
Return Value
Type: Microsoft.CommerceServer.Catalog..::.Product
A new Product containing the new product.
Exceptions
Exception | Condition |
---|---|
EntityDoesNotExistException | The definitionName does not exist. |
InvalidDefinitionUseException | The definitionName contains a variant property which is being used as a IdentifyingProductProperty for the catalog or the definitionName contains a normal property which is being used as a IdentifyingVariantProperty for the catalog. |
EntityAlreadyExistsException | The productId already exists. |
NotAuthorizedException | The caller is not authorized to perform this operation. |
Remarks
This method creates a new product in the catalog which can be identified by the productId and returns a Product object. You do not have to call the Save method after you call this method. You can use the returned Product object to access and update information on the product. If you make any changes to the product object you should call the Save method to save the changes to the catalog system.
The definitionName should:
Not be nullNothingnullptra null reference (Nothing in Visual Basic) or blank.
Not exceed 128 characters.
Be an existing product definition in the catalog system.
The productId should:
Not be nullNothingnullptra null reference (Nothing in Visual Basic) or blank.
Not exceed 256 characters.
Not already exist in the catalog.
The price of the product will be 0. If the definitionName does not contain variant properties, then the product will be created as a regular product and cannot contain variants. If the definitionName contains variant properties, then the product will be created as a product family and can contain variants. If the definitionName contains variant properties and one of the variant properties is the sane as the IdentifyingProductProperty of the catalog or one of the normal properties in the definitionName is the same as the IdentifyingVariantProperty of the catalog the product cannot be created in the catalog.
Examples
{
BaseCatalog baseCatalog = (BaseCatalog)catalogContext.GetCatalog(catalogName);
Product product = baseCatalog.CreateProduct(definitionName, productId);
// Once the product is created additional properties can be set on the product
product.DisplayName = "New Display name";
product.ListPrice = 19.99M;
// Finally save the changes to the catalog system by calling product.Save
product.Save();
return product;
}
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.