Is it possible that the following two lines of code in CatalogController.PrepareProductVariantModel:
decimal finalPriceWithoutDiscountBase = _taxService.GetProductPrice(productVariant, _priceCalculationService.GetFinalPrice(productVariant, false), out taxRate);
decimal finalPriceWithDiscountBase = _taxService.GetProductPrice(productVariant, _priceCalculationService.GetFinalPrice(productVariant, true), out taxRate);
could be replaced with:
Discount discount = null;
decimal discountAmount = decimal.Zero;
decimal finalPriceWithDiscountBase = _priceCalculationService.GetFinalPrice(productVariant, _workContext.CurrentCustomer, decimal.Zero, true, 1, out discount, out discountAmount);
decimal finalPriceWithoutDiscountBase = finalPriceWithDiscountBase + discountAmount;
finalPriceWithDiscountBase = _taxService.GetProductPrice(productVariant, finalPriceWithDiscountBase, out taxRate);
finalPriceWithoutDiscountBase = _taxService.GetProductPrice(productVariant, finalPriceWithoutDiscountBase, out taxRate);
? I trying to figure out if there's a situation where it wouldnt be equivalent but in the meantime, if someone finds a show stopper, let me know.
EDIT: I think the tax service must be applied after computing the amount without the discount otherwise we're adding a discount amount without taxes to an amount with taxes... I modified my suggested code.