InventorySku Class
This class provides functionality to manage properties of an inventory SKU.
Assembly: Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)
Implements functionality of the InventoryCatalog class. The attributes will contain information about the inventory catalog. The class contains methods to get and update product information.
public bool CreateAndDeleteInventorySkus()
{
bool result = true;
InventoryCatalog inventoryCatalog = null;
InventorySku inventorySku = null;
string inventoryCatalogName = "Default";
string productCatalogName = "Dummy Product Catalog";
string prefix = "Test";
InventoryContext inventoryContext = helper.InventoryContext;
#region Setup
/** Note: Adding the association with a product catalog is necessary before creating inventory skus
* for products and variants in that product catalog.
**/
try
{
//Get The Default Inventory Catalog
inventoryCatalog = inventoryContext.GetInventoryCatalog(inventoryCatalogName);
//Add Product Catalog association to this inventory catalog
inventoryCatalog.AddProductCatalog(productCatalogName);
inventoryCatalog.Save();
}
catch (Exception e)
{
Console.WriteLine("Unexpected Exception trying to create a sku " + e.Message);
throw e;
}
#endregion
try
{
//Creating an inventory sku for a product
inventorySku = inventoryCatalog.CreateSku(productCatalogName,prefix+" PID", 100, StockStatus.Enabled);
//Get the inventory sku
inventorySku = inventoryCatalog.GetSku(productCatalogName, prefix + " PID");
//Update the inventory sku
inventorySku.Backorderable = true;
inventorySku.BackorderLimit = 5;
//Saving the changes
inventorySku.Save();
//Delete inventory Sku
inventoryCatalog.DeleteSku(productCatalogName, prefix + " PID");
//Remove mapping
inventoryCatalog.RemoveProductCatalog(productCatalogName);
inventoryCatalog.Save();
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception when manipulating inventory skus" + e.Message);
result = false;
}
return result;
}
System..::.Object
Microsoft.CommerceServer.Catalog..::.CatalogObjectBase
Microsoft.CommerceServer.Inventory..::.InventorySku
Microsoft.CommerceServer.Catalog..::.CatalogObjectBase
Microsoft.CommerceServer.Inventory..::.InventorySku