Related products.
Currently for performance reasons I do a CatalogSearch to get a list of all of the products (and variants) in the catalog. This returns a DataSet which for constructing the variant relationships is just fine. The problem is that I want to be able to get the related products. The only way that I know of doing that is to convert the DataRow describing the product to a CS Product object as follows:
Microsoft.CommerceServer.Catalog.
Product product = catalogContext.GetProduct("MyCatalog", currentProductId);Then using this Product I can use the property RelatedProducts to get a DataSet containing the products that are related to this Product. This works but it is really slow. I have a feeling that the main bottleneck is the conversion (GetProduct) toMicrosoft.CommerceServer.Catalog.Product.Is there another way that I can get the related products using the product id? I get the product id from the search, which returns a
Microsoft.CommerceServer.Catalog.CatalogItemsDataSetif that is helpful.
Thank you.
Kevin
I'm sure that you're right about that being the bottleneck. Most likely, you don't need all of the data coming back from GetProduct, but you need more than you are getting from the search. My solution to this has been to add the extra fields that you need to the search options object you are executing the search with, and avoiding the conversion to a Product object altogether.
Ideally, you have a business-layer product object that wraps around the Commerce Server Product object. This wrapper can be created with a Commerce Server Product, or some subset of data instead. As it is used around the site, it will attempt to just work off of the subset of data it has. Only if some data is requested that is not in that subset, does it goes to the trouble of getting the actual Commerce Server Product object and incurring those costs.
When you perform your search, you create these product wrappers from the search results, feeding them the subset of the product data that you have and a null commerce server Product object. Then you use those wrappers throughout your site instead of the Commerce Server product object.
Of course, that's just one solution (lazy loading). I'm sure there are others, and the best fit will depend on your situation.
My apologies, Kevin, I misunderstood your initial post! I will try to find some time later today to look into what you were really asking, but hopefully someone else will come along with a solution before then.