Getting the most appropriate list of catalogs for the current user

I was looking at the documentation of CommerceContext.GetCatalogsForUser and there is surprisingly very little documentation compared to what the method actually does. Based on the user browsing the site this method attempts to retrieve the most appropriate list of catalogs for that user. And this is how:

If the user has a profile

           1. First try to get the catalogsetid from the user’s profile

Get the value of the catalogSetIdProperty attribute from the

CommerceServer/profiles/userProfile section.If the catalogSetIdProperty is not

specified in  web.config set it to AccountInfo.user_catalog_set

            Get the catalogsetId defined for the catalogSetIdProperty in the user’s profile

           

2. If the catalogSetId is null then get the catalogsetid from the user’s Organization profile

Get the value of the catalogSetIdProperty attribute from the

CommerceServer/profiles/ organizationProfile section. If the catalogSetIdProperty is

not specified in web.config set it to GeneralInfo.org_catalog_set

Get the catalogsetId defined for the catalogSetIdProperty in the user’s Organization

profile.

 

End // If the User has a profile

If the catalogSetId is not null Then

            Return the list of catalogs in the catalogset defined by this catalogSetId

Else If the catalogSetId is null Then

3. Get the catalogsetName from the commerceserver\catalog\catalogsets section in web.config.

If the user is Authenticated then

Get the value of the catalogsetName from the defaultAuthenticated attribute. If this attribute is not specifed in web.config then set the catalogsetName to “Registered User Default CatalogSet”

Else If the user is an Anonymous user Then

Get the value of the catalogsetName from the defaultAnonymous attribute. If this attribute is not specifed in web.config then set the catalogsetName to “Anonymous User Default CatalogSet”

 

            Return the list of catalogs belonging to this catalogsetName.

End If  

 

Things to note:

  1. As its name suggests a catalogset contains a list of product catalogs. You can use Business Desk to create catalog sets and associate a list of catalogs with that catalog set.
  2. A catalogset is represented by a name and a guid. When defining the catalogset in the profiles section in web.config use the guid. When defining the catalogset in the catalogsets section in web.config use the catalogset name.
  3. By default the catalog system creates two catalogsets. “Registered User Default CatalogSet” containing the list of catalogs for authenticated user’s and “Anonymous User Default CatalogSet” containing the list of catalogs for anonymous users. You should not delete these catalogsets from your catalog system.