Developer forum

Forum » Ecommerce - Standard features » Prices with discount

Prices with discount

Ivan Marijanović
Ivan Marijanović
Reply

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.productIdproductObject.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 minPriceDouble.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


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Ivan

The price provider does not calculate discount. That happens at a later stage - in the discount. You can use the Discount service to get the available product discounts. You have to use DiscountProvider which is not public, to actually calculate the discount, so you cannot. Also quantity discounts are depending on an order, so this is very tricky and I have no clean way for you to do this.

You should not make new instances of services. Instead use Dynamicweb.Services.Products to get the product service etc.

BR Nicolai

Votes for this answer: 1
 
Ivan Marijanović
Ivan Marijanović
Reply

Hi Nicolai,

Thank you for your answer! 

My question is that when we have products on discount and if they have only one price price is dispalyed correctlly wioth discount on product list even thou we dont have order yet.

For example here we have gridview of product list and we see price with discount here:

 

Ivan

 
Nicolai Pedersen
Reply

Yes - I understand.

But - DW does not calculate the discount for quantities above 1 unless the product is in the cart with minimum that quantity.... A limitation related to our implementation of the discounts.

BR Nicolai

 
Ivan Marijanović
Ivan Marijanović
Reply

Thank you!

Ivan

 

You must be logged in to post in the forum