Commerce Server Blog

Build world class ecommerce applications using Microsoft Commerce Server
  •  
  • Home
  • Advertise
  • Copyright Policy
  • Disclaimer
  • About

Commerce Server CategoryConfiguration Class

ravikanth | August 18, 2008

CategoryConfiguration class is used to configure the pre-loaded properties of a category object which includes child category and products.  Through this object, we can tell commerce server whether to fetch all products under a category (including sub categories) or products under that category only. In this article I am explaining how to fetch category products with the help of CategoryConfiguration class.

Requirement:

1.       If the category is root or parent then show all the products under that category (including products in sub categories).

2.       If the category is sub-category and doesn’t have any categories under it then show only those products.

Pre-requisites:

I created a catalogName “MySite” and top category named “Dance”. Under “Dance”, I have created two categories named “classic dance” and “break dance”. “Dance” category is having two products and sub-categories having one product each.

            string catalogName = “Mysite”;

            string categoryName = “Break Dance”;

            CatalogContext catalogContext = CommerceContext.Current.CatalogSystem;

            ProductCatalog catalog = catalogContext.GetCatalog(catalogName);

            CategoryConfiguration categoryConfig = new CategoryConfiguration();

            categoryConfig.RecursiveChildProducts = false;

           

            ProductCollection productCollection;

            CategoryCollection categoryCollection = null;

 

            if (categoryName == string.Empty)

            {

                productCollection = catalog.GetRootCategory(categoryConfig).ChildProducts;

            }

            else

            {

                Category category = null;

                category = catalog.GetCategory(categoryName, categoryConfig);

                categoryCollection = category.ChildCategories;

                if (categoryCollection.Count > 0)

                {

                    categoryConfig.RecursiveChildProducts = true;

                    category = catalog.GetCategory(categoryName, categoryConfig);

                }

                productCollection = category.ChildProducts

            }

            Response.Write(productCollection.Count.ToString());

 

In the above code, we are checking whether the category is having any child categories, if yes then we are getting all products under that category by setting the catalogConfiguration class property – RecursiveChildProducts to true. If the category doesn’t have any sub-categories then the products at the root are returned.

If I pass “Dance” value to category variable then I will get four products and If I pass “Break Dance” value to category variable then I will get one product.

Comments
No Comments »
Categories
commerce server 2007
Tags
CategoryConfiguration, commerce server, RecursiveChildProducts
Comments rss Comments rss
Trackback Trackback

Sign up for Newsletter


Categories

Quiz

  • Catalog Quiz for Beginners
  • Profile Quiz for Beginners
  • Quiz 1 for Advance Users
  • Quiz for Beginners

Recent Posts

  • RCXml2Resx.exe tool stops working
  • Commerce Server Profile Importer Tool
  • Marketing Web service Exception: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
  • Download Commerce Server 2009 Help Document
  • Commerce Server 2009 work with SharePoint 2010?
  • Failed to set value for profile property ‘email_address’.
  • ArgumentException: An item with the same key has already been added.
  • Please note that one or more items were removed from your order because the product is no longer sold.
  • How to Avoid Duplicate Orders Numbers in Commerce Server
  • Error: Microsoft.Commerce.Contracts.Faults.ItemDoesNotExistFault

Archives

  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008

Tags

add discounts add images to profile Advantages of commerce server approve discounts authentication auto login process automatic user creation basket Brand Management business tools campaign management Catalog catalog import Category CategoryConfiguration commerce server commerce server 2007 commerce server manager Commerce Server SP2 discounts ecommerce Estimation Installation inventory Kanth Koppala marketing system migration error Mojave operation components operation sequence Order subsystem Product profile profile subsystem property metadata purchase order quick checkout Ravi Ravi Kanth site cache refresh starter site tools transactions error Variant
(c) 2009 Commerce Server Blog. All rights Reserved. Articles cannot be reproduced without permission from the author.Write to me at kanth@ravikanth.net if you have any comments, questions, suggestions about this site or would like to send us a tip
About Us | Terms of Use | Disclaimer | Advertise .