Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Im not a heavy user of LINQ and as im still quite new to UC too im having trouble with what ought to be a simple query.
I have a product with several variants and i want to get the cheapest variant price for that product.
Here is what i have but i know its not right... I am working from the current product:
var x = from v in ucProduct.Variants
var x = select v.PriceGroupPrices.Min(p => p.Price).Value;
return x.Single();
I can the output From: £xxx on my page.
TIA
Arghh! Pasted the wrong code and forum wont let me edit! :(
Here it is again:
select v.PriceGroupPrices.Min(p => p.Price).Value;
Once i have the value I can then output
From: £xxx on my page.
One thing to keep in mind is that the lowest value amount might not mean that it's also the lowest price if you're working with multiple currency.
Take this example:
Variant priced at USD 1, EUR 1, and GBP 1. Which is the lowest? :)
Here's a quick bit of code that just grabs the lowest price based on the value without taking currency into account:
// Grab any product with variantsProduct product = Product.All().First(x => x.ParentProduct == null); // Find the cheapest price among all prices assigned to indivudla variants and then// find the variant with the lowest overall price. decimal? cheapestVariantPrice = product.Variants.Min(x => x.PriceGroupPrices.Min(y => y.Price)); foreach (var variant in product.Variants) { foreach (var price in variant.PriceGroupPrices) { Console.WriteLine("Variant {0} priced {1} in {2}".FormatWith(variant.VariantSku, price.Price, price.PriceGroup.Name)); } } Console.WriteLine("Cheapest variant priced {0}".FormatWith(cheapestVariantPrice));
Ah i wasnt a million miles off then.
Im making my online store deal only with GBP as thats what we will be selling in. Is this a mistake?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
LINQ to get the cheapest variant price
Hi,
Im not a heavy user of LINQ and as im still quite new to UC too im having trouble with what ought to be a simple query.
I have a product with several variants and i want to get the cheapest variant price for that product.
Here is what i have but i know its not right... I am working from the current product:
var x = from v in ucProduct.Variants
var x = select v.PriceGroupPrices.Min(p => p.Price).Value;
return x.Single();
I can the output From: £xxx on my page.
TIA
Arghh! Pasted the wrong code and forum wont let me edit! :(
Here it is again:
var x = from v in ucProduct.Variants
select v.PriceGroupPrices.Min(p => p.Price).Value;
return x.Single();
Once i have the value I can then output
From: £xxx on my page.
TIA
One thing to keep in mind is that the lowest value amount might not mean that it's also the lowest price if you're working with multiple currency.
Take this example:
Variant priced at USD 1, EUR 1, and GBP 1. Which is the lowest? :)
Here's a quick bit of code that just grabs the lowest price based on the value without taking currency into account:
Ah i wasnt a million miles off then.
Im making my online store deal only with GBP as thats what we will be selling in. Is this a mistake?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.