Posted on 10/06/2021 10:13:18
Hi
On solution we have different prices defined depending on ordering quantity. Now on products list we wont to show the lowest price defined so I am looping the Product.Prices and finding lowest price and displaying it in product list (I do this in ProductListFeed). It warsk until we have some discounts defined on products (for example 30% of on all products in Clearence group). I am trying to use DefaultPriceProvider in loop to get price with discount but without any success - I allways get null. Any ideas?
This is code:
if(product.GetLoop("Product.Prices").Count>0)
{
var priceLoop =product.GetLoop("Product.Prices");
Dynamicweb.Ecommerce.Products.Product prod = new Dynamicweb.Ecommerce.Products.Product();
Dynamicweb.Ecommerce.Products.ProductService srv = new Dynamicweb.Ecommerce.Products.ProductService();
prod = srv.GetProductById(productObject.productId, productObject.variantid,true);
Dynamicweb.Ecommerce.International.CurrencyService curService = new Dynamicweb.Ecommerce.International.CurrencyService();
var cur = curService.GetCurrency(product.GetString("Ecom:Product.Price.Currency.Code"));
Dynamicweb.Ecommerce.Prices.PriceProvider priceProvider = new Dynamicweb.Ecommerce.Prices.DefaultPriceProvider();
double minPrice= Double.MaxValue;
foreach(var priceInfo in priceLoop)
{
double currentQty = priceInfo.GetDouble("Ecom:Product.Prices.Quantity");
Dynamicweb.Ecommerce.Prices.PriceRaw pr =
(Dynamicweb.Ecommerce.Prices.PriceRaw)priceProvider.FindInformativePrice
(prod,currentQty,
productObject.variantid,
cur,
product.GetString("Ecom:Product.DefaultUnitID"),
user);
double currentPrice = priceInfo.GetDouble("Ecom:Product.Prices.PriceWithoutVAT");
if(pr!=null){
currentPrice = pr.Price;
}
if ( currentPrice < minPrice)
{
minPrice = currentPrice;
productObject.priceMin = minPrice.ToString();
}
}
} else {
productObject.priceMin = productObject.price;
}
Thanks in advance.
Ivan