Call GetActiveProductPrice API in Commerce runtime dynamics 365
In this blog, we learn how to call the GetActiveProductPrice API in the commerce runtime (CRT).
- We take ProductIds from cartLine but you also hardcode the ProductIds.
CartLine cartLine = ((AddCartLinesRequest)request).CartLines.FirstOrDefault();
List<long> productIds = new List<long>();
productIds.Add(cartLine.ProductId);
ChannelConfiguration channelConfigs = request.RequestContext.GetChannelConfiguration();
- Pass this ProductIds in the GetActiveProductPriceRequest and then execute the request.
GetActiveProductPriceRequest getActiveProductPriceRequest = new GetActiveProductPriceRequest()
{
ProductIds = productIds,
DateWhenActive = new DateTimeOffset(DateTime.Now, TimeSpan.Zero),
Context = new ProjectionDomain(channelConfigs.RecordId, 0),
QueryResultSettings = new QueryResultSettings(new PagingInfo(1000)),
IncludeSimpleDiscountsInContextualPrice = true
};
GetActiveProductPriceResponse pricesResponse = await request.RequestContext.ExecuteAsync<GetActiveProductPriceResponse>(getActiveProductPriceRequest).ConfigureAwait(false);
Comments