How to Search an Inventory Catalog

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

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.

Note

Because of the Microsoft SQL Server 2000 WHERE clause limit of 4000 characters, the SQL WHERE clause in the Commerce Server Catalog and Inventory System is also limited. This causes a limit of approximately 1400 characters for a basic catalog search when inventory query data is added to the WHERE clause text. This WHERE clause limit does not exist in Microsoft SQL Server 2005.

To search an inventory catalog

  1. Specify a search string.

  2. Use the SearchOptions object to specify search options.

  3. Use the GetSkus methods of the InventoryCatalog object to get an InventorySkuCollection object.

  4. 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);
        }
    }
}

See Also

Other Resources

How to Perform a Guided Search [API]