Product Variant price calculation optimization

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
Hi,

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.
11 年 前
I'm not sure that it would be right or wrong (needs some investigation). But could you please clarify about the optimization? Is it in not calling _priceCalculationService.GetFinalPrice method twice?
11 年 前
Precisely. Is in some caching going on in there that I did not see?

EDIT: I see what you mean, GetFinalPrice is not doing much when there's no tier prices apart from computing the discount. But a few ms saved is better than nothing I guess ;)
11 年 前
I'm not sure that it does not really save a lot of time because no additional database requests are made when are run
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.