Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

Get highest and lowest price of a Product

$
0
0

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.


Viewing all articles
Browse latest Browse all 6894

Trending Articles