How to Search an Inventory Catalog
You can search an inventory catalog for SKUs. To do this use one of the GetSkus methods of the InventoryCatalog object. You can specify search options and a search clause, or you can get all the SKUs in the catalog.
To search an inventory catalog
Specify a search string.
Use the SearchOptions object to specify search options.
Use the GetSkus methods of the InventoryCatalog object to get an InventorySkuCollection object.
Iterate through the returned dataset to access the individual SKUs.
Example
This example describes how to search for SKUs in an inventory catalog. The example first gets the inventory catalog. It then creates a search string. In this case it is searching for all inventory items with Status enabled. It then creates search options that specify the property by which to sort the returned SKUs. The example then searches for the SKUs and writes the product IDs of the returned items to the console.
public static void SearchSkus(InventoryContext inventoryContext, string inventoryCatalogName)
{
// Search the inventory catalog.
InventoryCatalog inventoryCatalog = inventoryContext.GetInventoryCatalog(inventoryCatalogName);
// Create the search string.
string searchClause = InventorySkusDataSetSchema.Status + " = " + Convert.ToInt16(StockStatus.Enabled);
// Create the search options.
SearchOptions searchOptions = new SearchOptions();
searchOptions.SetPaging(1, 20);
searchOptions.SortProperty = InventorySkusDataSetSchema.ProductId;
// Get the search results.
int total = 0;
InventorySkuCollection skuCollection = inventoryCatalog.GetSkus(searchClause, searchOptions, out total);
if (total > 0)
{
foreach (InventorySku inventorySku in skuCollection)
{
// Write the product ID to the console.
Console.WriteLine(inventorySku.ProductId);
}
}
}