Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
You can do that with IPriceService by using the method
IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKey> catalogKeys, PriceFilter filter);
or
IEnumerable<IPriceValue> GetPrices(MarketId market, DateTime validOn, IEnumerable<CatalogKeyAndQuantity> catalogKeysAndQuantities, PriceFilter filter);
The parameter catalogKeys is all variant's codes of that product
I'm glad that you are aware that the default implementation of IPriceDetailService is not cached, a few more comments:
Hi,
Using Commerce 12.3.1.
I am trying to find an efficient way to find the highest and lowest price of a product. For example:
Product - Tables (T001) has 3 variants under it; small (T001-SM) priced at $5, medium (T001-M)priced at $7 and large (T001-L) priced at $10. I want to get a range of the prices from minimum to maximum ($5 -$10). I am able to get the price of all variants using IPriceDetailService, but this will kill the website when it goes live. The next option is IPriceService, I know that it is cached and I am unable to get all the prices of product.
Below is the snippet using IPriceDetailService, it works but this is not recommended:
var priceDetailService = ServiceLocator.Current.GetInstance<IPriceDetailService>(); priceDetailService.List(content); //In this case I was passing the content reference of the product
Below is the snippet using IPriceService, but I am unable to get any prices as it gives a count of 0:
var priceService = ServiceLocator.Current.GetInstance<IPriceService>(); IContentLoader loader = ServiceLocator.Current.GetInstance<IContentLoader>(); var x1 = loader.Get<EntryContentBase>(content); var priceList = priceService.GetCatalogEntryPrices(new CatalogKey(x1.Code));
Any guidance on this will be helpful.