commerce hacker

I need to retrieve different a different CatalogSet for two different types of authenticated users. According the the doco, if I populate the UserObject profile AccountInfo.user_catalog_set field with the appropriate catalog set key/guid that the CommerceContext.GetCatalogsForUser() method will return the appropriate catalog set according to the documentation which states:

"The user catalog set and organization catalog set properties must contain a GUID that is the ID of the catalog set. GetCatalogsForUser"

So the quesiton then is "how does one obtain the guid for a catalog set" I can write a SQL query to retrive it by name:

Code Snippet

select CatalogSetID

from CatalogSet_Info

where CatalogSetName = "CustomerType1 CatalogSet"

or

select CatalogSetID

from CatalogSet_Info

where CatalogSetName = "CustomerType2 CatalogSet"

However given that the whole API seems to forego direct queries against the database, this just doesn't seem right. What other mechanism exist to achieve this I'm looking around the API's but can't find what I'm looking for.



Re: Commerce Server 2007 Retrieving CatalogSet's for different types of shoppers.

Joseph Johnson

chuckmed,

I believe the method you're looking for is:

Code Snippet
CommerceContext.Current.CatalogSystem.CatalogSetsContext.GetCatalogSets();

This returns an object of type Microsoft.CommerceServer.CatalogSets.CatalogSetCollection, which you can iterate through to get objects of type Microsoft.CommerceServer.CatalogSets.CatalogSet.

The CatalogSet class has a property called CatalogSetId which is the guid for that catalog set.






Re: Commerce Server 2007 Retrieving CatalogSet's for different types of shoppers.

Jeff Lynch - MVP

Here are two additional code samples used to retrieve the CatalogSetId.

For the CatalogSetId stored in the UserObject Profile:

CatalogSetId = (string)CommerceContext.Current.UserProfile.Properties["AccountInfo.user_catalog_set"].Value;

For the CatalogSetId stored in the Organization Profile:

CatalogSetId = (string)CommerceContext.Current.OrganizationProfile.Properties["GeneralInfo.org_catalog_set"].Value;

Once you have the CatalogSetId here is the code to return the CatalogSet object:

Guid myGuid = new Guid(CatalogSetId);

CatalogSet catalogSet = CommerceContext.Current.CatalogSystem.CatalogSetsContext.GetCatalogSet(myGuid);

I hope this helps!

Jeff Lynch

MVP Windows Server System - Commerce Server

http://codebetter.com/blogs/jeff.lynch