Developer forum

Forum » Ecommerce - Standard features » Get Asset Categories for variants

Get Asset Categories for variants

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Guys,

I have a project running on DW 9.14.
One of the requests is to expose AssetCategories in the PIM feed for both main products and Variants.
From what I see, no matter what I include in the fields, for Variants, I can only get the Image but not the asset categories.

Is there any Service that I can use to retrieve Asset categories based on ProductId and VariantId? Or any other method for that Matter? I know I can create a ProductViewModel based on the Variant information, but I am worried about the performance since the list is rather large.
Thank you,

Adrian


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

You have 2 options

You can get the categories from DetailGroupService and the assets from DetailService.GetDetails(). Problem is that it will probably give you too many DB calls as these services hides their bulk retrieval methods.

An alternative is to use Dynamicweb.Ecommerce.ProductCatalog.ViewModelFactory.CreateView(ProductListViewModelSettings settings, IEnumerable<long> productAutoIds) or CreateView(ProductViewModelSettings settings, IEnumerable<ProductInfoViewModel> productInfo) - they will return you a pageable list of products and will optimize the queries for the details.

I do not know how many products you are returning - so becareful on performance.

BR Nicolai

 

You must be logged in to post in the forum