Posts tagged ‘Virtual Catalog’

Force an update of a virtual catalog

A simple script to force commerce server to update all the products in virtual catalogs.

A few times in the past i have noticed that the virtual catalog doesn’t always update when a property is updated in the base catalog. Here is a simple solution.

static void Main(string[] args)
{

     CatalogContext context = CatalogContext.Create(new CatalogServiceAgent("http://yourhost/CatalogWebService/CatalogWebService.asmx"));

     CategoryConfiguration config = new CategoryConfiguration();

     config.RecursiveChildProducts = true;

     Category cat = context.GetCategory("Base Catalog", "", "en-us", config);

     foreach (Product p in cat.ChildProducts)
    {

     p["Description"] = DBNull.Value;
     p["DescriptionHtml"] = DBNull.Value;
     p.Save();

     }

     context.RebuildAllCatalogs(true);
}

You’ll notice that i set the description property to DBNull, you will need to include all properties you need updated in a manner similar to this.