Page 1 of 1

How to calculate discount

Posted: Wed Sep 02, 2009 8:19 am
by learnerbm
Hi all, I want to show the discount price of a product in a page. In some pages AbleCommerce overlines the MSRP price and shows Price near it. But I want to overline the Price info and I want to show price after discount price calculated. How can I get Discount value for a product like in the Basket?

Re: How to calculate discount

Posted: Wed Sep 02, 2009 6:49 pm
by mazhar
In order to calculate the discounted amount you can try some code like below

Code: Select all

protected LSDecimal GetDiscountedPrice(Product product)
    {
        LSDecimal discountedAmount = 0;
        VolumeDiscountCollection availableDiscounts = VolumeDiscountDataSource.GetAvailableDiscounts(product.ProductId);
        VolumeDiscount volumeDiscount = null;
        if (availableDiscounts.Count > 0)
        {
            volumeDiscount = availableDiscounts[0];
            discountedAmount = volumeDiscount.CalculateDiscount(1, 1, product.Price, product.Price);
        }
        return discountedAmount;
    }
In order to handle price display most probably you will need to modify product price control in ConLib/Utility folder.

Re: How to calculate discount

Posted: Thu Sep 03, 2009 12:05 am
by learnerbm
Thank you very much Mazhar, it works definitely how I want.

Best regards

Re: How to calculate discount

Posted: Tue Jul 24, 2012 6:03 pm
by sloDavid
Mazhar, is it possible that there are multiple available discounts? I'm also concerned about what if I already have quantities in the basket. Should we instead do something like:

Code: Select all

foreach (VolumeDiscount vd in availableDiscounts) {
  discountedAmount += vd.CalculateDiscount(1, 1 + qtyAlreadyInBasket, product.Price, product.Price + totalValueOfBasketItems);
}
Do you know what totalValue and lineItemValue mean, precisely? Do they relate to the extended price?