How to calculate discount

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
learnerbm
Ensign (ENS)
Ensign (ENS)
Posts: 8
Joined: Wed Sep 02, 2009 8:13 am

How to calculate discount

Post by learnerbm » Wed Sep 02, 2009 8:19 am

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?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to calculate discount

Post by mazhar » Wed Sep 02, 2009 6:49 pm

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.

learnerbm
Ensign (ENS)
Ensign (ENS)
Posts: 8
Joined: Wed Sep 02, 2009 8:13 am

Re: How to calculate discount

Post by learnerbm » Thu Sep 03, 2009 12:05 am

Thank you very much Mazhar, it works definitely how I want.

Best regards

sloDavid
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 92
Joined: Thu Feb 25, 2010 12:34 pm

Re: How to calculate discount

Post by sloDavid » Tue Jul 24, 2012 6:03 pm

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?

Post Reply