How to calculate discount
How to calculate discount
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
In order to calculate the discounted amount you can try some code like below
In order to handle price display most probably you will need to modify product price control in ConLib/Utility folder.
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;
}
Re: How to calculate discount
Thank you very much Mazhar, it works definitely how I want.
Best regards
Best regards
Re: How to calculate discount
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:
Do you know what totalValue and lineItemValue mean, precisely? Do they relate to the extended price?
Code: Select all
foreach (VolumeDiscount vd in availableDiscounts) {
discountedAmount += vd.CalculateDiscount(1, 1 + qtyAlreadyInBasket, product.Price, product.Price + totalValueOfBasketItems);
}